FFI: calling Haskell from C++?

Wolfgang Thaller wolfgang.thaller at gmx.net
Tue Sep 13 11:39:11 EDT 2005

> we have tried long and hard to call Haskell functions from C++ using
> the FFI mechanism but without success.

Don't forget to say which platform you're on - the solution might be  
slightly platform-dependent.

>   $ ghc -fffi Foo.o Foo_stub.o main.cpp
>   main.o(.text+0x22): In function `main':
>   main.cpp: undefined reference to `__stginit_Foo()'

> #ifdef __GLASGOW_HASKELL__
> extern void __stginit_Foo ( void );
> #endif

This should be...

extern "C" void __stginit_Foo ( void );

>   main.o(.eh_frame+0x11): undefined reference to  
> `__gxx_personality_v0'
>   collect2: ld returned 1 exit status

On Mac OS X, all you need to do is add -lstdc++ to your ghc command  
line; it may or may not be that easy on other platforms.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org//pipermail/glasgow-haskell-users/attachments/20050913/99280494/attachment.htm

More information about the Glasgow-haskell-users mailing list