GHC compiling shared library linking problem

Richard Zetterberg richard.zetterberg at googlemail.com
Mon Oct 22 14:16:12 CEST 2012


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hello and thank you for the reply

Yes! It seems the details from my first mail (10/15/12 3:25 PM) fell
out. Here is the relevant parts from that mail:

"
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/;

Information about the system:

Linux 2.6.32-5-amd64 Debian 6.0.6
GHC 7.4.1
GCC 4.7.2
GNU ld 2.22
"

I tried adding -fPIC and -dynamic to 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/ -fPIC -dynamic;

And got this error:

    ../src/Shared.hs:1:1:
        Could not find module `Prelude`
        Perhaps you haven't installed the "dyn" libraries for package
`base'? 	
        Locations searched:
            Prelude.hs
            Prelude.lhs
            ../src/Prelude.hs
            ../src/Prelude.lhs
            /usr/lib/ghc/base-4.5.0.0/Prelude.dyn_hi

Does that mean I can just install those libraries or do have to
compile ghc from source and pass some flags to include those librares?

Best regards
Richard


On 10/22/12 1:24 PM, Simon Marlow wrote:

> I think you're trying to make a shared library from Haskell code,
> right? You don't say what platform, but it looks like x86_64/Linux
> or maybe OS X.  On these platforms, code that goes into a shared
> library must be compiled with -fPIC.  You will also need to compile
> with -dynamic, in order to link against the shared versions of the
> RTS and the other Haskell libraries.
> 
> Cheers, Simon
> 
> 
> 
> 
> 
>> 
>> Best regards Richard
>> 
>> On 10/15/12 6:44 PM, Carter Schonwald wrote:
>> 
>> 
>> -----BEGIN PGP SIGNATURE----- Version: GnuPG/MacGPG2 v2.0.17
>> (Darwin) Comment: GPGTools - http://gpgtools.org Comment: Using
>> GnuPG with Mozilla - http://www.enigmail.net/
>> 
>> iQIcBAEBAgAGBQJQfmGPAAoJEP99n2Mvs+ma5KwP/1ZMZzZtNmQ7EUJSPg1mB3w7 
>> Wh1KQtgLrfcCggfeMlA/XOtUE+pgtN66uarbi9iaqLULH4fLm/h6v12zSmaqG1uU 
>> XKuaIRtr886+bcFG/fXO0pW7OGbaF/w0nQN06iRqbFrce0f/U3VGHp8BqJNZFhSK 
>> qIHRM+WweM95LV9tgrCAeI3C2sGR4GkzhUunCCAOSZ8MfEwFxPV4OsmuCjKGcCcb 
>> GZXXhOynGhbLa8mg29dQNytt01AMgBBiRSWLHVFW6IfUxPk7uuQp33Q6wvjOUyA4 
>> kJIUz9BU9IiPUeVdO2sg+fBB1ehOV2qPiqHf0xoJ1mpH6qd3KnUcJXsXrTXK4piz 
>> lo2lCOlqxspBiByX4HzyLE6pA+8OZcREO5GOHo5V4iI0RQAwkjaqARAU/6VVXHC0 
>> fQbPJf8U1CQZZamkuoTgUfKcOHLFYIqVq9p8Ar1dykT74okAyMR+FU0ExWTbr/Xs 
>> 7oGD+Q44geh65FkkeLUoKIUD+aV35HQE6GL9O/OjKm1aMg3yGA5bM6UUiAw2FgqE 
>> jfZoHc9frO/WMP1XgEkKQjtupUCH92ol/PpyPbFJqfnxMvvvI+lYEEIL90XPudmS 
>> 5ygqeinIVwBKGVb6D08rLC1OzaS0dFasOjOeWYM12epbZsy9WCzIl+U14TFgy/Ze 
>> la4rqefI8sdBK1cQslYu =RN8H -----END PGP SIGNATURE-----
>> 
>> _______________________________________________ 
>> Glasgow-haskell-users mailing list 
>> Glasgow-haskell-users at haskell.org 
>> http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
>> 
> 
> 

-----BEGIN PGP SIGNATURE-----
Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Mozilla - http://www.enigmail.net/

iQIcBAEBAgAGBQJQhTkLAAoJEP99n2Mvs+maat0P/RIqXRmsSwHw/9N7pcHPa3PC
6PtI6NvTb3djy0H/ErI5weKZbFQbfvh0vdB4uqH59/QA/IOCe6+SY0C1ez6n8W3/
nyGLi+EIPgENkzSFm2u/8L7+S0CL2A0sR+Yvx+3Ei7xvIcwa/3hKuvPYGNBzjODq
3RrYqQFA/AR/3A2yv7OafBtjALuntit4QJod8NdCc6mvgp2fcp0KcId+H3wjbhWU
n053mWhJjMDY3DzOqDQi6BaSCj8+d4GZPOX1gdaxyIdXa7RM23QoLhHOAFoOPu2u
PLIjQy9qRyMD9yXr36gii/N1Z32EtcyBYE5uyd7P6uqRv7cn4LRAWCNfT2icyjHG
ph96YXYsTcQRgYh8HBlPWPgvQWLiBRs68RJBGLT1l5nAFzoMSFZYpb/Oh9J8d232
pfV4MwvakG1JVJuwJlGOfuWZJoTP+pMUA9GY+XTeXlPnGNlh5ATOs5BHDlECK52h
U6m1qGQfaTlr+E4S4Af9N5XnwinV+YzXhVbmzAQtOFOgbQ+lW5b8zBev1CT8hUtt
r4PNJdp44BJ2jBMx3VCrL/qWusDlQA0CrobOzHHHRlKEJG2jZnpTxT2VMOjpTC0I
rQb/ehhosNvyaQglJ0RDjwf8596d5AfhYefv76iU1HBuf03JHQhh5wf+ltDotVc9
0Ld1V2LL1WtSnqs72r/n
=mf8i
-----END PGP SIGNATURE-----



More information about the Glasgow-haskell-users mailing list