简体   繁体   中英

Error linking with static Boost::Python library on Ubuntu x64

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 with no problems with options set to: 手动构建了Boost :: Python,并且选项设置为没有问题:

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

Next' I'm trying to build my module (pydsrc.cpp) using with the same options, but it fails at the gcc linker stage. 构建模块(pydsrc.cpp),但在gcc链接器阶段失败。 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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM