Hi,
I’m hitting a problem trying create shared haskell libs to be linked into a C program on Mac OS X.
I’m using the latest download for Leopard from the GHC page:
http://www.haskell.org/ghc/dist/6.10.1/witten/ghc-6.10.1-powerpc-apple-darwin.tar.bz2
I can get basic executables working fine (with a C main() #including ghc’s stub header), using something like:
ghc -optc-O invnorm.c InverseNormal.o InverseNormal_stub.o -o cTest
I started off using the following line to try to create a shared lib:
ghc --make -no-hs-main -optl '-shared' -o Inv.so InverseNormal.hs
This doesn’t work on mac os x because Apple’s gcc annoyingly takes different switches, so I changed it to:
ghc --make -no-hs-main -optl '-dynamiclib' -o Inv.dylib InverseNormal.hs
Which still fails at the final link giving:
Linking Inv.dylib ...
Undefined symbols:
"_environ", referenced from:
_environ$non_lazy_ptr in libHSbase-4.0.0.0.a(PrelIOUtils.o)
ld: symbol(s) not found
I’ve seen similar things before, and I believe if you have full control over the source you just slip in a:
#define environ (*_NSGetEnviron())
Sure enough, I can find references to environ in, for example HsBase.h
Problem (as I see it) is that references to environ are already wrapped up in the static lib libHSbase-4.0.0.0.a, so without recompiling Haskell we can’t alter the C definition now. However, given that packager must have made this behave when he compiled the distribution there must be a way to make Mac gcc accept _envrion symbols??
Has anyone seen this before / can confirm my analysis / and by any chance have a solution?
Many thanks,
Phil.