FFI: calling Haskell from C++?

Rich Neswold rich.neswold at gmail.com
Tue Sep 13 11:45:04 EDT 2005


On 9/13/05, Felix Breuer <felix at fbreuer.de> wrote:
> 
> $ ghc -fffi Foo.o Foo_stub.o main.cpp
> main.o(.text+0x22): In function `main':
> main.cpp: undefined reference to `__stginit_Foo()'
> main.o(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
> collect2: ld returned 1 exit status
> 

In main.cpp, you need to define __stginit_Foo(void) like this:

extern "C" void __stginit_Foo(void);

Specifying the "C" linkage with prevent the compiler from looking for a 
name-mangled version of the function.

To fix the second problem, you need to shut off exception handling 
(specifying the -fno-exceptions option ought to do this. I don't know how to 
pass compiler option via ghc, though.

-- 
Rich

AIM : rnezzy
ICQ : 174908475
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org//pipermail/glasgow-haskell-users/attachments/20050913/40304962/attachment-0001.htm


More information about the Glasgow-haskell-users mailing list