不能boost库链接到共享库
问题描述:
在1.63.0库libboost_regex-mt.a
连接升压到共享库中,我得到的错误:不能boost库链接到共享库
/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使用下面的命令(又见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.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
[email protected]
libboost_regex-mt.so.1.63.0*
[email protected]
libboost_regex.so.1.63.0*
的threading_multi命令仍然建立无-fPIC,例如''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” – sakra