I googled around how to build statically but I am still struggling to run this. For example this Static linking with boost python, I am getting errror
/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
What am I doing wrong?
Object files intended to be linked into a shared library must be compiled as position-independent code. With gcc
and clang
that requires -fPIC
compiler command line option. Static .a
libraries are normally compiled without that option and that is the reason you observe this linker error. See How to compile static library with -fPIC from boost.python for more details.