Subject:
[ruby-ffi] Re: how do I properly attach to this function?
From:
Jason Toy
Date:
11/3/11 4:41 PM
To:
ruby-ffi

I've added a trunk function to fix this.

On Nov 2, 4:24 pm, Jason Toy <jason...@gmail.com> wrote:
> I have a function  that is called like this in a c ++ app:
>    CompactLangDet::DetectLanguage( .....)
>
> I see that C++ symbols are not visible in C so I ran nm on the library
> to see the names of the functions:
> 0000000000002820 T
> __ZN14CompactLangDet14DetectLanguageEPKNS_15DetectionTablesEPKcibbbbS4_i8La nguagePS5_PiPdS7_Pb
> 00000000000028a0 T __ZN14CompactLangDet21DetectLanguageVersionEv
> 0000000000004440 T
> __ZN18CompactLangDetImpl24DetectLanguageSummaryV25EPKN14CompactLangDet15Det ectionTablesEPKcibbbS5_i8LanguagebiS6_PS6_PiPdS8_Pb
> 000000000013b180 s
> __ZZN18CompactLangDetImpl24DetectLanguageSummaryV25EPKN14CompactLangDet15De tectionTablesEPKcibbbS5_i8LanguagebiS6_PS6_PiPdS8_PbE18default_cld_tables
>
> So I tried running:
>
> require 'ffi'
> module MyLib
>   extend FFI::Library
>   ffi_lib "#{Dir.pwd}/cld.so"
>    #attach_function "CompactLangDet::DetectLanguage",
> [ :int, :buffer_in,:int,:bool,:bool,:bool,:bool,:buffer_in,:int,:int,:int,:int,:dou ble,:int,:bool ], :int
>    attach_function
> "__ZN14CompactLangDet14DetectLanguageEPKNS_15DetectionTablesEPKcibbbbS4_i8L anguagePS5_PiPdS7_Pb",
> [ :int, :buffer_in,:int,:bool,:bool,:bool,:bool,:buffer_in,:int,:int,:int,:int,:dou ble,:int,:bool ], :int
> end
>
> but I still get an error:
> FFI::NotFoundError: Function
> '__ZN14CompactLangDet14DetectLanguageEPKNS_15DetectionTablesEPKcibbbbS4_i8L anguagePS5_PiPdS7_Pb'
> not found in [/Users/jtoy/sandbox/ccld/cld.so]
>         from /Users/jtoy/.rbenv/versions/1.9.3-preview1/lib/ruby/gems/1.9.1/
> gems/ffi-1.0.10/lib/ffi/library.rb:247:in `attach_function'
>
> What is the correct way for me to reference this function?