Foreign function Intf./GHC newbie question

Hours of poring over documentation has failed to provide me with the answer to what I am sure is a simple question for most of you. Your help is appreciated. I want to compile a Haskell program that calls a foreign C function. I'm using GHC. When GHC links, it says it can't find my C function. That is not surprising, because I can't figure out how I'm supposed to tell GHC where to find my C function. This is what I've got: ------ FILE: ffi.hs {-# OPTIONS -fglasgow-exts #-} {-# OPTIONS -#include "myc.h" #-} module Main where foreign import ccall "supernumber" supernumber :: Int bongo :: Int bongo = supernumber + 1 main = do putStrLn (show bongo) ------ FILE: myc.c static int supernumber() { return(72); } ------ FILE: myc.h static int supernumber(); ------- END OF FILES When I do "ghc ffi.hs," it comes back: "ffi.o(.text+0xa8):fake: undefined reference to `supernumber' " I am guessing that I need to tell it where myc.c is. Perhaps I have to compile myc.c first using gcc? That seems inconvenient. Any hints? I am using Windows XP and GHC 6.4, if that matters. _________________________________________________________________ Is your PC infected? Get a FREE online computer virus scan from McAfee® Security. http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963

Hello John, Saturday, November 26, 2005, 5:59:41 AM, you wrote: JZ> I want to compile a Haskell program that calls a foreign C function. I'm JZ> using GHC. When GHC links, it says it can't find my C function. That is JZ> not surprising, because I can't figure out how I'm supposed to tell GHC JZ> where to find my C function. in order to link in C module you should compile it separatelly (better by ghc itself - it will setup all needed options and then call gcc) and add its .o module to the cmdline: ghc -c myc.c ghc --make ffi.hs myc.o also try the following: ghc --make ffi.hs myc.c may be it will also work -- Best regards, Bulat mailto:bulatz@HotPOP.com
participants (2)
-
Bulat Ziganshin
-
John Zenger