c++ - 提升 python 静态构建

标签 c++ 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

我做错了什么?

最佳答案

要链接到共享库中的目标文件必须编译为与位置无关的代码。使用 gccclang 需要 -fPIC 编译器命令行选项。静态 .a 库通常在没有该选项的情况下编译,这就是您观察到此链接器错误的原因。参见 How to compile static library with -fPIC from boost.python了解更多详情。

关于c++ - 提升 python 静态构建,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50907916/

相关文章:

python - Boost.Python | .so 文件中的符号,但我收到 ImportError : undefined symbol

python - boost::python:使用回调

c++ - 为什么不解决 fork 过程中的变化?

c++ - 错误 : "Attempt to use a deleted function" when moving a promise

c++ - 密文长度不是 cryptopp 中 block 大小的倍数

python - 多态异常处理 : How to catch subclass exception?

python - 使用 boost::python,如何将结构 vector 作为字典列表返回给 Python?

c++ - 混淆 myClass ** p1 和 myClass *p2[5]

c++ - 在 DLL 中使用 Windows API

python - 与从 python 3.5.2 源构建的 libpython3.5m.so 相比,libpython3.so 是什么?