<HTML>
<HEAD>
<TITLE>Re: [Haskell-cafe] Shared library creating on Mac OS X</TITLE>
</HEAD>
<BODY>
<FONT SIZE="4"><FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:11pt'><BR>
I&#8217;ve made a bit of progress here after reading up on Darwin&#8217;s GCC a bit more:<BR>
<BR>
ghc --make -no-hs-main -fPIC -optl '-dynamiclib' -optl '-undefined' -optl 'suppress' -optl '-flat_namespace' &nbsp;-o Inv.dylib InverseNormal.hs <BR>
<BR>
This dies when it links against haskell&#8217;s own libraries, my guess is because they are position dependant. &nbsp;So the only way I see forward would be to recompile haskell with &#8220;&#8211;fPIC&#8221;.<BR>
<BR>
This seems like a lot of hassle, so I&#8217;m shelving this for now &#8211; if anyone has any other (less distruptive) ways to proceed give me a shout &#8211; even if it means linking statically.<BR>
<BR>
Cheers,<BR>
<BR>
Phil.<BR>
<BR>
Linker error now is:<BR>
<BR>
<BR>
ld: warning codegen with reference kind 13 in _stg_CAF_BLACKHOLE_info prevents image from loading in dyld shared cache<BR>
<B>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<BR>
</B>collect2: ld returned 1 exit status<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
On 10/01/2009 02:26, &quot;Phil&quot; &lt;pbeadling@mail2web.com&gt; wrote:<BR>
<BR>
</SPAN></FONT></FONT><BLOCKQUOTE><FONT SIZE="4"><FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:11pt'>Hi,<BR>
<BR>
I&#8217;m hitting a problem trying create shared haskell libs to be linked into a C program on Mac OS X.<BR>
<BR>
I&#8217;m using the latest download for Leopard from the GHC page:<BR>
<a href="http://www.haskell.org/ghc/dist/6.10.1/witten/ghc-6.10.1-powerpc-apple-darwin.tar.bz2">http://www.haskell.org/ghc/dist/6.10.1/witten/ghc-6.10.1-powerpc-apple-darwin.tar.bz2</a><BR>
<BR>
I can get basic executables working fine (with a C main() #including ghc&#8217;s stub header), using something like:<BR>
ghc -optc-O invnorm.c InverseNormal.o InverseNormal_stub.o -o cTest<BR>
<BR>
I started off using the following line to try to create a shared lib:<BR>
<BR>
&nbsp;ghc --make -no-hs-main -optl '-shared' -o Inv.so InverseNormal.hs<BR>
<BR>
This doesn&#8217;t work on mac os x because Apple&#8217;s gcc annoyingly takes different switches, so I changed it to:<BR>
<BR>
ghc --make -no-hs-main -optl '-dynamiclib' -o Inv.dylib InverseNormal.hs<BR>
<BR>
Which still fails at the final link giving:<BR>
<BR>
Linking Inv.dylib ...<BR>
Undefined symbols:<BR>
&nbsp;&nbsp;&quot;_environ&quot;, referenced from:<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_environ$non_lazy_ptr in libHSbase-4.0.0.0.a(PrelIOUtils.o)<BR>
ld: symbol(s) not found<BR>
<BR>
I&#8217;ve seen similar things before, and I believe if you have full control over the source you just slip in a:<BR>
<BR>
#define environ (*_NSGetEnviron())<BR>
<BR>
Sure enough, I can find references to environ in, for example HsBase.h<BR>
<BR>
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&#8217;t alter the C definition now. &nbsp;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??<BR>
<BR>
Has anyone seen this before / can confirm my analysis / and by any chance have a solution?<BR>
<BR>
Many thanks,<BR>
<BR>
Phil.<BR>
<HR ALIGN=CENTER SIZE="3" WIDTH="95%"></SPAN></FONT><FONT FACE="Consolas, Courier New, Courier"><SPAN STYLE='font-size:10pt'>_______________________________________________<BR>
Haskell-Cafe mailing list<BR>
Haskell-Cafe@haskell.org<BR>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><BR>
</SPAN></FONT></FONT></BLOCKQUOTE>
</BODY>
</HTML>