links to this page:    
View this PageEdit this PageUploads to this PageHistory of this PageTop of the SwikiRecent ChangesSearch the SwikiHelp Guide
Last updated at 12:34 pm UTC on 17 January 2006
Some FFI Questions & Answers culled from the Squeak Email List. (If you have an FFI question, post it to the email list, not here.)


I have written a C++ shared library and when I attempt to use it in squeak with FFI, I have the classical "Error : can't find function address".

Do you know whether it is possible to use C++ librarries with FFI in the same way that I can use C libraries ? – Julien Bourdon (posted on squeak-dev, 3 May 2004)


Are you taking into account the name mangling that C++ will perform on your function identifiers?

E.g., 'int foo(int)' will typically be associated with a symbol not entirely unlike '__Z3fooi', and you must supply this mangled name to the FFI rather than simply 'foo'.

If you have 'nm' then run it on your .o files to see the symbols that it really contains. If you have 'c++filt' you can also pipe the output from 'nm' into it to obtain the original human-readable prototypes. (Some versions of 'nm' have an option to demangle the symbols implicitly before displaying them.)

Beware that different compilers (or even different versions of the same compiler) will mangle names differently. There is no easy, portable way to predict how an indentifier might be mangled during compilation. Your code will likely not run on two different platforms (or the same platform with two different compilers). For example, you might have several versions of c++filt (with numeric suffixes denoting different versions of the mangling scheme that each of them recognises).

Another approach would be to turn off mangling explicitly for all functions that you want to export to the FFI. Declare their prototypes up-front inside an 'extern "C" { ... }' section, before defining them. This would be far more portable than attempting to predict how the C++ compiler will mangle your symbols. – Ian Piumarta