提升 python 静态构建
boost python build statically
我用谷歌搜索了如何静态构建,但我仍在努力运行。例如这个 Static linking with boost python,我收到错误
/python_boost$ g++ -o hello.o -c hello.cpp -Wall -fPIC
-I/usr/include/python2.7 /python_boost$ g++ -shared -o libhello.so hello.o -lpython2.7 /usr/lib/x86_64-linux-gnu/libboost_python.a
/usr/bin/ld:
/usr/lib/x86_64-linux-gnu/libboost_python.a(from_python.o): relocation
R_X86_64_32 against `.rodata.str1.8' can not be used when making a
shared object; recompile with -fPIC
/usr/lib/x86_64-linux-gnu/libboost_python.a: error adding symbols: Bad
value collect2: error: ld returned 1 exit status
我做错了什么?
要链接到共享库中的目标文件必须编译为与位置无关的代码。使用 gcc
和 clang
需要 -fPIC
编译器命令行选项。静态 .a
库通常在没有该选项的情况下编译,这就是您观察到此链接器错误的原因。有关详细信息,请参阅 How to compile static library with -fPIC from boost.python。
我用谷歌搜索了如何静态构建,但我仍在努力运行。例如这个 Static linking with boost python,我收到错误
/python_boost$ g++ -o hello.o -c hello.cpp -Wall -fPIC -I/usr/include/python2.7 /python_boost$ g++ -shared -o libhello.so hello.o -lpython2.7 /usr/lib/x86_64-linux-gnu/libboost_python.a /usr/bin/ld: /usr/lib/x86_64-linux-gnu/libboost_python.a(from_python.o): relocation R_X86_64_32 against `.rodata.str1.8' can not be used when making a shared object; recompile with -fPIC /usr/lib/x86_64-linux-gnu/libboost_python.a: error adding symbols: Bad value collect2: error: ld returned 1 exit status
我做错了什么?
要链接到共享库中的目标文件必须编译为与位置无关的代码。使用 gcc
和 clang
需要 -fPIC
编译器命令行选项。静态 .a
库通常在没有该选项的情况下编译,这就是您观察到此链接器错误的原因。有关详细信息,请参阅 How to compile static library with -fPIC from boost.python。