0

I would like to build library (say "mylib", static or shared, doesn't really matter) that internally uses boost (boost::asio in particular). Library public interface doesn't depend on any boost types.

Library supposed be used by Qt application, and I don't want to introduce any boost dependencies into app's build scripts (it uses qmake currently) and I need the "mylib" to be only dependency. Library build system is CMake. I tried to build shared library with statically linked boost but I'm getting errors like:

/usr/bin/ld: /usr/lib/x86_64-linux-gnu/libboost_system.a(error_code.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
/usr/lib/x86_64-linux-gnu/libboost_system.a: error adding symbols: Bad value

Primary target target/toolchain is gcc x64 (Linux) but it would be good to have crossplatform solution (at least mingw64 and MacOS X).

Creating static library is an option too, but I couldn't figure out how to include static boost libs into "mylib"

mbg033
  • 501
  • 5
  • 18

1 Answers1

1

You can't use code built for a static library inside a dynamic library. Shared libraries require position-independent code. You could take the object files that were used to build Boost shared libraries, and stuff them all into a .a file and use that. Or munge your Boost build to add -fPIC to the flags for compiling its static libraries.

hyc
  • 1,387
  • 8
  • 22