boost1.62.0编译静态库fPIC链接问题

本文详细探讨了在应用中引入Boost库时遇到的编译错误,重点在于如何在使用-fPIC选项时解决`relocationR_X86_64_32`问题。作者提供了对gcc.jam文件的分析,并提出了针对链接共享库的正确配置策略。
摘要由CSDN通过智能技术生成

问题背景:应用中引入了boost库,引用库使用-fPIC编译选项 为了能够直接使用静态库进行编译链接

编译错误: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/local/lib/libboost_system.a: error adding symbols: Bad value 

分析处理:
➜  boost_1_62_0 pwd
/root/3rd/boost_1_62_0
➜  boost_1_62_0 vim tools/build/src/tools/gcc.jam  
 # 将403 修改为  if $(link) = shared ||  $(link) = static
 400 rule setup-fpic ( targets * : sources * : properties * )
 401 {
 402     local link = [ feature.get-values link : $(properties) ] ;
 403     if $(link) = shared
 404     {
 405         local target = [ feature.get-values target-os : $(properties) ] ;
 406
 407         # This logic will add -fPIC for all compilations:
 408         #
 409         # lib a : a.cpp b ;
 410         # obj b : b.cpp ;
 411         # exe c : c.cpp a d ;
 412         # obj d : d.cpp ;
 413         #
 414         # This all is fine, except that 'd' will be compiled with -fPIC even
 415         # though it is not needed, as 'd' is used only in exe. However, it is
 416         # hard to detect where a target is going to be used. Alternatively, we
 417         # can set -fPIC only when main target type is LIB but than 'b' would be
 418         # compiled without -fPIC which would lead to link errors on x86-64. So,
 419         # compile everything with -fPIC.
 420         #
 421         # Yet another alternative would be to create a propagated <sharedable>
 422         # feature and set it when building shared libraries, but that would be
 423         # hard to implement and would increase the target path length even more.
 424
 425         # On Windows, fPIC is the default, and specifying -fPIC explicitly leads
 426         # to a warning.
 427         if ! $(target) in cygwin windows
 428         {
 429             OPTIONS on $(targets) += -fPIC ;
 430         }
 431     }
 432 }


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Erice_s

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值