how to force compilation of Boost to use -fPIC

后端 未结 2 1540
一向
一向 2020-12-15 05:44

The team on which I work produces a shared library for use in Python. This library is entirely C++ and we use Boost to expose to python. Because we cannot guarantee that o

相关标签:
2条回答
  • 2020-12-15 06:10

    I believe boost automatically uses -fPIC when compiling a shared library (.so file), but the below command uses -fPIC when compiling a static library (.a file) too.

    This worked for me on boost 1.46.1:

    sudo ./bjam cxxflags=-fPIC cflags=-fPIC -a ... install
    

    The ... is where you add additional flags like threading=multi or --layout=tagged, and optionally the list of projects to build (for example: --with-regex).

    Note: using both cflags and cxxflags is unnecessary, only one is needed. See comments below.

    Reference links:

    • https://cmake.org/Wiki/TubeTK/Build_Instructions#Boost_.28optional.29
    • http://lists.boost.org/boost-users/2010/07/60682.php
    0 讨论(0)
  • 2020-12-15 06:23

    Just for convenience, I combined previous answer and comments to it:

    sudo ./bjam cxxflags=-fPIC -a --with-system install
    

    --with-system is not necessary, but it's a place where you can add other boost compile options

    It works for me at CentOS 7 with boost 1.67

    0 讨论(0)
提交回复
热议问题