How to compile static library with -fPIC from boost.python

↘锁芯ラ 提交于 2019-11-27 20:34:11

问题


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?


回答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.



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


来源:https://stackoverflow.com/questions/12418838/how-to-compile-static-library-with-fpic-from-boost-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!