【发布时间】:2017-04-12 12:10:37
【问题描述】:
将 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,其他文件(包括 regex 库中的 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 标志?
【问题讨论】: