编译报错:/usr/bin/ld: /usr/local/lib/libgflags.a(gflags.cc.o): relocation R_X86_64_32S against `.rodata‘

当使用catkin_make编译ROS程序时遇到gflags相关错误,原因是gflags未以PIE(Position Independent Executable)模式编译。为解决此问题,需要重新编译gflags,设置BUILD_SHARED_LIBS选项为ON,然后执行make和sudo make install。完成后再重新编译ROS程序,问题即可解决。
摘要由CSDN通过智能技术生成

一、问题描述

自己是因为编译 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.
在这里插入图片描述

  • 4
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值