Results 1 to 2 of 2
Hi All,
I am getting "relocation R_X86_64_32 against `.bss' can not be used when making a shared object; recompile with -fPIC" error when compiling a shared object with optimization option ...
- 01-20-2010 #1Just Joined!
- Join Date
- Nov 2009
- Posts
- 43
"relocation R_X86_64_32 against `.bss' can not be used when making a shared..." error
Hi All,
I am getting "relocation R_X86_64_32 against `.bss' can not be used when making a shared object; recompile with -fPIC" error when compiling a shared object with optimization option -O2 enabled using GNU GCC:
First, I compile a static library, which is used by the shared object, as follows:
Below is how I compile the shared object, which uses libclassreg.a:Code:g++ -g -O2 -c common/src/packet-class-registry.cc ar -cvq libclassreg.a common/src/packet-class-registry.o
Is this a problem regarding the order of compiler options ? (-O2 appears before -fPIC)Code:g++ -g -O2 -fPIC -c packet-v4.cc -o packet-v4.o gcc -shared -Wl,-soname,libv4.so.1 -o libv4.so.1.0 packet-v4.o -Lcommon/lib -Lconf/configLib/lib -lclassreg -lNsConf /usr/bin/ld: common/lib/libclassreg.a(packet-class-registry.o): relocation R_X86_64_32 against `.bss' can not be used when making a shared object; recompile with -fPIC common/lib/libclassreg.a: could not read symbols: Bad value collect2: ld returned 1 exit status make: *** [libv4.so] Error 1
Or is it something else ?
Thanks.
- 01-20-2010 #2Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 8,974
I use the -fPIC options for both static and dynamic libraries. It doesn't hurt the static library, plus it allows you to either use the static library in a shared one, or to extract the .o files from it to build into another shared library. Since your shared library is taking components from libclassreg.a, you need to build that static library and ALL of its components with the -fPIC option. Best option, make -fPIC part of all of your CFLAGS settings and rebuild everything to be sure they are all relocatable.
Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!


Reply With Quote