【问题标题】:Error linking with static Boost::Python library on Ubuntu x64在 Ubuntu x64 上与静态 Boost::Python 库链接时出错
【发布时间】:2012-02-15 20:55:15
【问题描述】:

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

我已经使用 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 上成功。有没有人遇到过类似的问题或知道可能是什么解决方案?任何帮助或线索如何正确构建模块将不胜感激。

干杯

【问题讨论】:

    标签: python gcc boost linker ubuntu-10.04


    【解决方案1】:

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

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

    【讨论】:

    • 我也试过用 fPIC 重新编译 boost 库 - 不幸的是没有运气。我已经放弃并放弃了在动态变体中编译我的模块的静态版本,但感谢您的回答。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多