无法将boost库链接到共享库

时间:2017-04-12 12:10:38

标签: c++ linux gcc boost

将boost 1.63.0库libboost_regex-mt.a链接到共享库后,我收到错误:

/usr/bin/ld: /usr/local/lib/libboost_regex-mt.a(instances.o): relocation R_X86_64_32S against `.rodata' can not be used when making a shared object; recompile with -fPIC
/usr/local/lib/libboost_regex-mt.a: could not read symbols: Bad value

我实际上已经使用以下命令使用-fPIC编译了boost(另请参阅here):

./bjam '-sBUILD=<cxxflags>-fPIC <linkflags>-fPIC' --without-mpi --without-python --without-iostreams --layout=tagged link=shared,static

在进行bjam调试构建时,似乎bjam似乎只尊重某些源文件的-fPIC,其他文件(包括来自正则表达式库的instances.cpp)在没有它的情况下编译:

gcc.compile.c++ bin.v2/libs/regex/build/gcc-4.8/release/link-static/threading-multi/instances.o

    "g++"  -ftemplate-depth-128 -O3 -finline-functions -Wno-inline -Wall -pedantic -pthread -m64  -DBOOST_ALL_NO_LIB=1 -DNDEBUG  -I"." -c -o "bin.v2/libs/regex/build/gcc-4.8/release/link-static/threading-multi/instances.o" "libs/regex/build/../src/instances.cpp"

如何强制bjam对所有文件使用-fPIC标志?

1 个答案:

答案 0 :(得分:1)

Build boost 1.63,共享库:

./b2 --without-mpi --without-python --without-iostreams --layout=tagged link=shared runtime-link=shared link=static install

threading = multi:

./b2 --without-mpi --without-python --without-iostreams --layout=tagged threading=multi link=shared runtime-link=shared link=static install

“正则表达式”结果:ls *regex*

libboost_regex.a
libboost_regex-mt.a
libboost_regex-mt.so@
libboost_regex-mt.so.1.63.0*
libboost_regex.so@
libboost_regex.so.1.63.0*
相关问题