当前位置:网站首页>Boot1.62.0 compilation static library FPIC link problem

Boot1.62.0 compilation static library FPIC link problem

2022-06-09 08:25:00 Erice_ s

The problem background : The application introduces boost library , Reference library usage -fPIC Compilation options In order to compile links directly using static libraries

 Compile error :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 

 Analyze and process :
*  boost_1_62_0 pwd
/root/3rd/boost_1_62_0
*  boost_1_62_0 vim tools/build/src/tools/gcc.jam  
 #  take 403  It is amended as follows  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 }


原网站

版权声明
本文为[Erice_ s]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/160/202206090815329027.html