
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hello
This is the first time I'm mailing to this list, so I hope I have come
to the right place.
The problem I have is that I get a linker error when compiling a
shared library with GHC. This problem occurred after I updated GHC
from 7.0.3 to 7.4.1. Here is the error itself:
/usr/bin/ld: ../src/Shared.so relocation R_X86_64_32S against
`ghczmprim_GHCziTypes_ZC_con_info` can not be used when making a
shared object; recompile with -fPIC
../src/Shared.so: could not read symbols: Bad value
collect2: error: ld returned 1 exit status
Here is the ghc command:
ghc -O2 --make -no-hs-main -optl '-shared' -optc '-DMODULE=Shared'
- - -o ../bin/pet_assembler_core.so Shared ../src/shared/module_init.c
- - -i../src/;
Shared.hs is the file where I specify the interface for the library,
it only has one function:
1 {-# LANGUAGE ForeignFunctionInterface #-}
2
3 module Shared where
4
5 import qualified Data.ByteString as BS
6 import Foreign.Ptr (Ptr)
7 import Foreign.Storable (poke)
8 import Foreign.Marshal.Utils (copyBytes)
9 import Foreign.Marshal.Alloc (mallocBytes)
10 import Foreign.C.Types (CSize, CChar)
11 import Foreign.C.String
12 import Data.ByteString.Unsafe (unsafeUseAsCStringLen)
13 import Assembly.Data
14 import qualified Assembly as ASM
15
16 type PPString = Ptr (Ptr CChar)
17 type PSize = Ptr CSize
18
19 foreign export ccall assemble :: PPString -> PSize -> CString ->
IO Int
And the module_init.c contains initialization of the module:
1 #define CAT(a,b) XCAT(a,b)
2 #define XCAT(a,b) a ## b
3 #define STR(a) XSTR(a)
4 #define XSTR(a) #a
5
6 #include