[Haskell-cafe] FFI, C/C++ and undefined references

Daniel Fischer daniel.is.fischer at web.de
Thu Jan 14 17:23:12 EST 2010


Am Donnerstag 14 Januar 2010 22:19:08 schrieb Miguel Mitrofanov:
> Works fine here (Mac OS X 10.5):
>
> MigMit:ngram MigMit$ ghc --make Main.hs srilm.o
> [1 of 2] Compiling LM               ( LM.hs, LM.o )
>
> LM.hs:9:0: Warning: possible missing & in foreign import of FunPtr
> [2 of 2] Compiling Main             ( Main.hs, Main.o )
> Linking Main ...

Thanks Miguel.
Yes, works here (openSuse 11.1), too (kind of):

(move the typedef out of the #else clause in srilm.h, because my g++ 
doesn't know Ngram)

$ g++ -c srilm.c
$ ghc --make Main.hs srilm.o
[1 of 2] Compiling LM               ( LM.hs, LM.o )                   

LM.hs:1:11:
    Warning: -#include is deprecated: No longer has any effect

LM.hs:13:0: Warning: possible missing & in foreign import of FunPtr
[2 of 2] Compiling Main             ( Main.hs, Main.o )            
Linking Main ...
$ ./Main                 
0.0                                                                
Speicherzugriffsfehler

Fixing the two warnings (removing the {-# INCLUDE #-} pragma and changing 
the declaration of deleteLM to
foreign import ccall "srilm.h &deleteLM" 
    c_dlm :: FunPtr ((Ptr Ngram) -> IO ())
), I get
$ ghc -fforce-recomp --make Main.hs srilm.o
[1 of 2] Compiling LM               ( LM.hs, LM.o )
[2 of 2] Compiling Main             ( Main.hs, Main.o )
Linking Main ...
$ ./Main
0.0
$



More information about the Haskell-Cafe mailing list