Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can not be used when making a shared object; recompile with -fPIC

I tried to install a library but I have got the following error after running make. How to recompile with flag?

make Scanning dependencies of target pwrutils Linking CXX shared library libpwrutils.so /usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/libboost_system.a(error_code.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC ,/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/libboost_system.a: error adding symbols: Bad value collect2: error: ld returned 1 exit status make[2]: * [libpwrutils/libpwrutils.so.1.0] Error 1 make[1]: * [libpwrutils/CMakeFiles/pwrutils.dir/all] Error 2 make: *** [all] Error 2

like image 773
Kasia Avatar asked Jan 07 '17 22:01

Kasia


1 Answers

In case if someone runs into this, and adding the fPIC flag to your project doesn't help:

I had the same problem, and my library had the -fPIC flag set up correctly within my CMakeLists, and I could verify it when looking at the compilation logs, for example, I saw: /usr/bin/c++ -fPIC ... etc.

Then I realized I link against couple other libraries, so I had to recompile both of them with the -fPIC, and that's where the problem was.

like image 89
vicrucann Avatar answered Nov 10 '22 07:11

vicrucann