Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 compile a static library (libboostpython.a) with -fPIC from boost.python?

like image 249
simon Avatar asked Sep 14 '12 05:09

simon


2 Answers

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.
like image 95
Maxim Egorushkin Avatar answered Oct 13 '22 08:10

Maxim Egorushkin


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
like image 43
Meir Drago Avatar answered Oct 13 '22 06:10

Meir Drago