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

Brandon S. Allbery KF8NH allbery at ece.cmu.edu
Wed Jan 13 23:40:45 EST 2010


On Jan 13, 2010, at 23:28 , DNM wrote:
> Sorry.  In my haste to paste in the .c file, I left out all the  
> include
> statements.  I do have #include "srilm.h" there (which to my non-
> C/C++ mind seems stupid -- why the hell would you need to import
> the header file for the code that it's a header *for*?)


Really, the only reason in this case is that there is no equivalent  
for `extern "C"' that you can apply to a function definition, only to  
a declaration.  The rationale is that everything that works with the  
function, including its definition, needs to see that declaration, so  
rather than repeat it in the definition you #include the declaration.

In GHC, this is the kind of thing that lands in the .hi file; the  
tradeoff is you need to have up to date .hi files for everything that  
needs to see that information, which can lead to dependency loops.   
GHC has a ".hs-boot" hack to work around this.  No free lunch....

-- 
brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery at kf8nh.com
system administrator [openafs,heimdal,too many hats] allbery at ece.cmu.edu
electrical and computer engineering, carnegie mellon university    KF8NH


-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 195 bytes
Desc: This is a digitally signed message part
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20100113/c62cf682/PGP.bin


More information about the Haskell-Cafe mailing list