I’ve made a bit of progress here after reading up on Darwin’s GCC a bit more:

ghc --make -no-hs-main -fPIC -optl '-dynamiclib' -optl '-undefined' -optl 'suppress' -optl '-flat_namespace'  -o Inv.dylib InverseNormal.hs

This dies when it links against haskell’s own libraries, my guess is because they are position dependant.  So the only way I see forward would be to recompile haskell with “–fPIC”.

This seems like a lot of hassle, so I’m shelving this for now – if anyone has any other (less distruptive) ways to proceed give me a shout – even if it means linking statically.

Cheers,

Phil.

Linker error now is:


ld: warning codegen with reference kind 13 in _stg_CAF_BLACKHOLE_info prevents image from loading in dyld shared cache
ld: absolute addressing (perhaps -mdynamic-no-pic) used in ___stginit_haskell98_Array_ from /usr/local/ghc/6.10.1/lib/ghc-6.10.1/haskell98-1.0.1.0/libHShaskell98-1.0.1.0.a(Array__1.o) not allowed in slidable image
collect2: ld returned 1 exit status






On 10/01/2009 02:26, "Phil" <pbeadling@mail2web.com> wrote:

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.

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe