无法将速推库链接到共享库

Cannot link boost library to shared library

本文关键字:链接 共享      更新时间:2023-10-16

将 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(另请参阅此处(:

./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 标志?

Build boost 1.63,共享库:

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

线程=多 :

./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*