how to force compilation of Boost to use -fPIC

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

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


Another solution:

./bootstrap.sh
./b2 cxxflags=-fPIC cflags=-fPIC

Tags:

C++

Boost