Skip to content Skip to sidebar Skip to footer

How To Compile Static Library With -fpic From Boost.python

By default, libboostpython.a is compiled without -fPIC. But I have to make a python extension and it is a dynamic library with -fPIC that links to static libraries. How can I compi

Solution 1:

There are a couple options you could use:

  • Compile boost from source and pass extra compiler options to bjam. E.g. bjam ... cxxflags='-fPIC'. That would compile every boost source file as position independent code.
  • Use boost in the form of shared libraries. In this case you probably want to ship boost shared libraries along with your application to make sure the appropriate version of boost is used. You can link your executable with '-Wl,-rpath,$ORIGIN' flag, so that when the dynamic linker searches for shared libraries required by your executable it looks for them in the directory where the executable is. See man ld.so for more details on $ORIGIN.

Solution 2:

Note that if you already run bjam once you need to clear the targets first it is helpful also to print the commands by applying -d+2:

./bjam clean && 
./bjam -d+2 link=static cxxflags="-fPIC" install

Post a Comment for "How To Compile Static Library With -fpic From Boost.python"