在 Ubuntu x64 上链接静态 Boost::Python 库时出错

发布于 2025-01-06 03:42:08 字数 1594 浏览 0 评论 0原文

我一直在尝试在运行时链接和链接静态配置中为 x64 linux 构建一个小型 Python 模块,但不幸的是没有成功。我在 Ubuntu x64 10.04 上使用 Boost::Python v.1.47 以及 gcc 4.4.3 和 Python 2.6.5 环境。

我已经使用 b2 手动构建 Boost::Python,选项设置为:

toolset=gcc variant=release address-model=64 link=static runtime-link=static

Next' 没有任何问题,我正在尝试使用 bjam 构建我的模块(pydsrc.cpp)使用相同的选项,但在 gcc 链接器阶段失败。以下是构建阶段的最后几行:

...
gcc.compile.c++ ../bin.v2/libs/python/build/gcc-4.4.3/release/address-model-64/link-static/runtime-link-static/object/function_doc_signature.o
gcc.archive ../bin.v2/libs/python/build/gcc-4.4.3/release/address-model-64/link-static/runtime-link-static/libboost_python.a
gcc.link.dll bin/gcc-4.4.3/release/address-model-64/link-static/runtime-link-static/pydsrc.so
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/4.4.3/crtbeginT.o: relocation R_X86_64_32 against `__DTOR_END__' can not be used when making a shared object; recompile with -fPIC
/usr/lib/gcc/x86_64-linux-gnu/4.4.3/crtbeginT.o: could not read symbols: Bad value
collect2: ld returned 1 exit status

"g++"    -o "bin/gcc-4.4.3/release/address-model-64/link-static/runtime-link-static/pydsrc.so" -Wl,-h -Wl,pydsrc.so -shared -Wl,--start-group "bin/gcc-4.4.3/release/address-model-64/link-static/runtime-link-static/pydsrc.o" 
 "../bin.v2/libs/python/build/gcc-4.4.3/release/address-model-64/link-static/runtime-link-static/libboost_python.a"   -lutil -lpthread -ldl   -Wl,--end-group -static -m64

在 Win7 x64 上使用 msvc9 工具集编译它,没有遇到太大困难,但在 Ubuntu 上无法成功。有没有人遇到过类似的问题或知道可能有什么解决方案?任何如何正确构建模块的帮助或线索将不胜感激。

干杯

I've been trying to build a small Python module for x64 linux in runtime-link and link static configuration and unfortunately with no success. I'm using using Boost::Python v.1.47 on Ubuntu x64 10.04 with gcc 4.4.3 and Python 2.6.5 environment.

I've build Boost::Python manually using b2 with no problems with options set to:

toolset=gcc variant=release address-model=64 link=static runtime-link=static

Next' I'm trying to build my module (pydsrc.cpp) using bjam with the same options, but it fails at the gcc linker stage. Below are the last lines from the build stage:

...
gcc.compile.c++ ../bin.v2/libs/python/build/gcc-4.4.3/release/address-model-64/link-static/runtime-link-static/object/function_doc_signature.o
gcc.archive ../bin.v2/libs/python/build/gcc-4.4.3/release/address-model-64/link-static/runtime-link-static/libboost_python.a
gcc.link.dll bin/gcc-4.4.3/release/address-model-64/link-static/runtime-link-static/pydsrc.so
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/4.4.3/crtbeginT.o: relocation R_X86_64_32 against `__DTOR_END__' can not be used when making a shared object; recompile with -fPIC
/usr/lib/gcc/x86_64-linux-gnu/4.4.3/crtbeginT.o: could not read symbols: Bad value
collect2: ld returned 1 exit status

"g++"    -o "bin/gcc-4.4.3/release/address-model-64/link-static/runtime-link-static/pydsrc.so" -Wl,-h -Wl,pydsrc.so -shared -Wl,--start-group "bin/gcc-4.4.3/release/address-model-64/link-static/runtime-link-static/pydsrc.o" 
 "../bin.v2/libs/python/build/gcc-4.4.3/release/address-model-64/link-static/runtime-link-static/libboost_python.a"   -lutil -lpthread -ldl   -Wl,--end-group -static -m64

On Win7 x64 using msvc9 toolset I compiled it with no major difficulties, but I cannot success on Ubuntu. Has anyone come across similar problem or know what might be a solution? Any help or clue how to properly build the module would be greatly appreciated.

Cheers

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

愁以何悠 2025-01-13 03:42:08

尝试通过 cxxflags 指令包含 PIC(位置无关代码)编译标志。所以在你的情况下是这样的:

toolset=gcc variant=release address-model=64 cxxflags=-fPIC link=static runtime-link=static

Try include the PIC (position-independent code) compile flag via the cxxflags directive. So in your case something like:

toolset=gcc variant=release address-model=64 cxxflags=-fPIC link=static runtime-link=static
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文