stx
stx

Reputation: 123

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 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

Upvotes: 0

Views: 957

Answers (1)

jbrownbridge
jbrownbridge

Reputation: 11

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

Upvotes: 1

Related Questions