Mark Storer
Mark Storer

Reputation: 15870

Trying to build with boost filesystem: "relocation … can not be used when making a shared object; recompile with -fPIC"

Is this the linux/g++ version of static vs shared libraries?

Ubuntu 18.04, boost 1.65, g++ 7.5.0, cmake 3.10.2, GNU make 4.1. Pretty much everything at the default version for ubuntu 18.04, plus the "latest" boost version available via apt-get. (btw, is there a more recent version available for a more recent ubuntu, or is apt just that far behind?)

I'm trying to port software that uses a number of different boost components (chrono, filesystem, proram_ptions, regex, system, thread, timer, and unit_test_framework) to an NVidia Jetson TX2 board... which uses the aforementioned version of ubuntu on BOTH it's dev board and host machine.

The hurdle I'm trying to clear at the moment is that linking the first shared lib in cmake: add_library( SHARED ...) fails in g++ with the error from the title. The 'blah blah blah' portion mentions a specific entry point within boost filesystem.

I conclude that I need to rebuild boost filesystem with the requested build flags: -fPIC. Shocking, I know. I seem to recall boost being its own unique snowflake in regards to its build system, so that'll be fun. At least cmake is the devil I know.

Do the libboost*-dev apt packages come with everything I need to rebuild, or do I need to go get the relevant version's source directly? I tried using apt-file to see what went where... but given how many different .c?? and .?? and so forth extensions are out there, I'm not even sure I'm searching boost::filesystem's file list for the right thing.

At some point I'll need to cross compile this stuff for the dev board (arm) instead of for the host machine (amd64), but one headache at a time...

Upvotes: 0

Views: 518

Answers (2)

Mark Storer
Mark Storer

Reputation: 15870

I ended up dropping back and punting: In cmake, I

set(BOOST_USE_STATIC_LIBS OFF)

In retrospect, this seems obvious.

:wq

Upvotes: 0

Botje
Botje

Reputation: 30972

Have you considered rebuilding Boost using Conan? Benefits:

  • The sharp corners of the build process have already been sanded off;
  • You can easily cross-compile by plugging in a profile for the ARM cross-compiler;
  • You can pin which version of Boost you want.
  • It integrates really well with CMake

Upvotes: 1

Related Questions