[Haskell-cafe] ffi linking problem

Stefan O'Rear stefanor at cox.net
Wed May 30 00:57:54 EDT 2007


On Wed, May 30, 2007 at 12:28:43AM -0400, jeff p wrote:
> Hello,
> 
> >No, but ghc does pass a lot of funny flags...
> >
> >Double check ccall v. stdcall in the import declaration.  That bites a
> >lot of people on Windows.
> >
> My import statement originally looked like:
> 
>    foreign import ccall "mylib.h myFun" my_fun :: CDouble -> IO (Ptr 
>    CDouble)
> 
> and my original linker error was an undefined reference to 'myFun'.
> 
> Changing the import statement to:
> 
>    foreign import stdcall "mylib.h myFun" my_fun :: CDouble -> IO (Ptr 
>    CDouble)
> 
> results in the linker complaining about undefined reference to 'myFun at 24'.

That is very very very suspicious.  the number after the @ is the
number of bytes of argument data, which should be 8 for a single
CDouble on x86 - not 24. 

> I also tried throwing in "static" but it seems to have no effect.

What does the definition in the library look like?  To be compatible
with that import it should be:

double *myFun(double);

NOT any of:

double *my_fun(double);

static double *myFun(double);

double myFun(double);

I suspect you may have the two names in the import statement swapped.

Stefan


More information about the Haskell-Cafe mailing list