I am not able to compile a shared library with GCC 3.2

Donatas Vyzas donatas@viesulas.ktu.lt
Tue Apr 4 17:23:00 GMT 2006


I did not get any answer to my question from anyone in this mailing 
list, but looks like I found the answer by myself. After some googling, 
I found out, that the problem was that I didn't specify -fPIC flag for 
the gcc during linking:

$ gcc -fPIC -shared -o libtest.sl test.o
$ nm libtest.sl |grep myFunct
000014f0 T myFunct
000014d8 T myFunct

Looks like it is OK with the example below, however, I have one archive 
library (consisting of object files compiled with -fPIC flag), that gcc 
cannot convert to shared library. As it is a separate issue, I'll post 
it in a new letter.

Donatas Vyzas

Donatas Vyzas wrote:
> Hi!
>
> I am not able to compile a shared library with a GCC 3.2 on a HP-UX 
> 11.0 (parisc 1.1) .
> $ gcc -v
> Reading specs from /usr/local/lib/gcc-lib/hppa2.0n-hp-hpux11.00/3.2/specs
> Configured with: ./configure  : (reconfigured) ./configure  : 
> (reconfigured) ./configure  : (reconfigured) ./configure  : 
> (reconfigured) ./configure  : (reconfigured) ./configure  : 
> (reconfigured) ./configure  : (reconfigured) ./configure  : 
> (reconfigured) ./configure  : (reconfigured) ./configure  : 
> (reconfigured) ./configure
> Thread model: posix
> gcc version 3.2
> $ cat test.c
> int myFunct()
> {
>        int i = 1;
>        return i++;
> }
> $ gcc -fPIC -c test.c
> $ gcc -shared -o libtest.sl test.o
> /usr/ccs/bin/ld: DP relative code in file /var/tmp//ccMDztre.o - 
> shared library must be position
>    independent.  Use +z or +Z to recompile.
> collect2: ld returned 1 exit status
>
> What I am doing wrong? Thanks for your help.
>
> Donatas



More information about the Gcc-help mailing list