[Haskell-cafe] Building a shared library with FFI on x86_64

Eric Webster ew at uw.edu
Thu Jan 27 20:59:06 CET 2011


I have a project that involves building a shared library containing code 
generated by GHC and exposed using the foreign function interface to 
other C programs that link against it. I'm able to build a functioning 
library without issue on 32bit x86 systems using GHC 6.8.2 and 6.12.3. 
When I try to build on a 64bit x86 system I get a relocation error that 
advises I include -fPIC. Including -fPIC does not help though. I'm 
wondering if I'm either doing something wrong or if this could be a 
problem with GHC.

I've created and attached a small example that illustrates this issue.

When building on 64bit x86 with GHC 7.0.1 and -fPIC and -dynamic I get 
the following error. (Similar with GHC 6.12.3)
/usr/bin/ld: CLibrary.o: relocation R_X86_64_PC32 against 
`CLibrary_testFunctionCWrapper_srt' can not be used when making a shared 
object; recompile with -fPIC
/usr/bin/ld: final link failed: Bad value

When building on 64bit x86 with GHC 7.0.1 and -fPIC and without -dynamic 
I get the following error (Similar with GHC 6.12.3 and 6.8.2)
/usr/bin/ld: 
/home/CIRG/ew/local/lib/ghc-7.0.1/base-4.3.0.0/libHSbase-4.3.0.0.a(Base__1.o): 
relocation R_X86_64_32S against `a local symbol' can not be used when 
making a shared object; recompile with -fPIC
/home/CIRG/ew/local/lib/ghc-7.0.1/base-4.3.0.0/libHSbase-4.3.0.0.a: 
could not read symbols: Bad value

When building on 32bit x86 with GHC 6.12.3 I get no error regardless of 
-fPIC or -dynamic.
When building on 32bit x86 with GHC 6.8.2 I get no error regardless of 
-fPIC and without -dynamic.

Any advice would be appreciated! Thanks.
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: CLibrary.hs
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20110127/df446bcd/attachment.asc>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: Makefile
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20110127/df446bcd/attachment.txt>


More information about the Haskell-Cafe mailing list