[Haskell-cafe] Building a shared library with FFI on x86_64
ew at uw.edu
Thu Jan 27 23:36:14 CET 2011
Thanks to http://www.well-typed.com/blog/30 I was able to figure out
what I was doing wrong. Replacing "-optl -shared" with just "-shared"
and using "-dynamic" allows linking to complete. :D
On 2011-01-27 11:59 AM, Eric Webster wrote:
> 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)
> relocation R_X86_64_32S against `a local symbol' can not be used when
> making a shared object; recompile with -fPIC
> 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.
More information about the Haskell-Cafe