Operating System - HP-UX
1832152 Members
3376 Online
110038 Solutions
New Discussion

Re: gcc -shared in HPUX 11 32 bit

 
SOLVED
Go to solution
Bryan lim
Occasional Contributor

gcc -shared in HPUX 11 32 bit

Dear all,

I compiled a few files using
"gcc -fPIC" to obtain *.o.

Then, I run
"gcc -shared -o abc.so *.o"

The error I got is as follows:
"/usr/bin/ld: DP relative code in file /var/tmp/ccKSMmXd.o - shared library must
be position
independent. Use +z or +Z to recompile.
collect2: ld returned 1 exit status"

I could not find the file "ccKSMmXd.o" in that directory. Can anyone advise what is wrong with it? The system is HPUX 11 (32-bit)

-Bryan
6 REPLIES 6
Deepak Extross
Honored Contributor

Re: gcc -shared in HPUX 11 32 bit

Never mind - thats a temporary object file, which would have been deleted by ld when it exited.
As it says, recompile but this time pass the +z flag to gcc.
Bryan lim
Occasional Contributor

Re: gcc -shared in HPUX 11 32 bit

Thanks for the reply.

I read from somewhere that the -fPIC should equivalent to +z/+Z , right?

I was not able to obtain the output file (*.so) I need, using the gcc -shared command.

Please advise.
Deepak Extross
Honored Contributor

Re: gcc -shared in HPUX 11 32 bit

Are you linking any other libraries / object files into the final executable? Maybe one or more of them are not PIC - compliant?
Bryan lim
Occasional Contributor

Re: gcc -shared in HPUX 11 32 bit

All the object files, *.o, were compiled successfully using gcc -fPIC.

However, error occured when I am running gcc - shared. What confused me is that the error is related to 'ld'.

Could it be because of the 32-bit environment? Or, perhaps some 64-bit shared library files are required?

Please advise.
Santosh Nair_1
Honored Contributor
Solution

Re: gcc -shared in HPUX 11 32 bit

Brian,

You can NOT mix 32-bit and 64-bit object in an excutable. They must all be the same bitness. As for -fPIC, that is the gcc equivalent of +z.

Typically this type of error happens to me when the linker (ld) is trying to build a shared object and one of the objects was NOT build with the position indepent code flag (-fPIC/+z). Are you linking these objects (either the *.o or *.so) with any other libraries (other than libc)?

-Santosh
Life is what's happening while you're busy making other plans
Bryan lim
Occasional Contributor

Re: gcc -shared in HPUX 11 32 bit

you are so right, Santosh.

I think I am mixing up the shared libraries required. I dont have the 64 bit shared libraries required.

Thanks for your advise