FFI question
Ian Piumarta
ian.piumarta at inria.fr
Mon May 3 15:25:01 UTC 2004
On 03 May 2004, at 07:23, liste..squeak wrote:
> 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 adress".
>
> Do you know whether it is possible to use C++ librarries with
> FFI in the same way that I can use C libraries ?
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
More information about the Squeak-dev
mailing list
|