1826843 Members
4427 Online
109704 Solutions
New Discussion

Re: Compiling error

 
SOLVED
Go to solution
George Bell
New Member

Compiling error

I am using gcc to create a shared
object. I am receiving this error:
/bin/ld: DP relative code in file
mesg.o - shared library must be
position independent. Use +z or +Z to
recompile.

I am using -fPIC to create the shared
objects, but am still receiving this
error.

Should I be using this to compile the
object as well?
4 REPLIES 4
H.Merijn Brand (procura
Honored Contributor

Re: Compiling error

create shared objects:

# cc -Ae +Z -c test.c
# gcc -fPIC -c test.c

create a shared lib:

# ld -b -o test.sl test.o

HTH, HAND
Enjoy, Have FUN! H.Merijn
Steven Gillard_2
Honored Contributor

Re: Compiling error

Yes, you must use the -fPIC flag when compiling all object files, otherwise you will receive this error. In your case its complaining about mesg.o - I would remove this object file and make sure it is recompiled with -fPIC.

Regards,
Steve
George Bell
New Member

Re: Compiling error

I am using -fPIC for the object file, do I need to compile the c file with this option as well?
Steven Gillard_2
Honored Contributor
Solution

Re: Compiling error

Yes, thats what I meant. The .c file must be compiled into a .o file with -fPIC. You don't need to specify this option when building the shared library from the .o files.

Regards,
Steve