一、问题描述
自己是因为编译 ros 程序,执行 catkin_make
的时候报 gflags 的错。
/usr/bin/ld: /usr/local/lib/libgflags.a(gflags.cc.o): relocation R_X86_64_32S against `.rodata' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: /usr/local/lib/libgflags.a(gflags_reporting.cc.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: /usr/local/lib/libgflags.a(gflags_completions.cc.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: 最后的链结失败: 输出不可表示的节
collect2: error: ld returned 1 exit status
二、解决方法
主要原因是 gflags 编译默认不是共享库,需要保证 gflags 编译成共享库
因此需要重新编译 gflags, 并重新安装 gflags 。
cd build/
cmake .. -DBUILD_SHARED_LIBS=ON
make
sudo make install
然后重新编译自己的程序,就可以编译成功了~~~~
参考文献
[1] wolfbill. relocation R_X86_64_32S against `.rodata’ can not be used when making a shared object; recompile with -fPIC #2171 . https://github.com/BVLC/caffe/issues/2171, 2016-08-26/2022-06-21.