2

I have a Qt application that uses the boost logger library. I want to make it a standalone. However, after I managed the libraries for static linking, the application is still dependent on boost libraries. The libraries that I included are:

    ..../boost_1_61_0_b1/stage/lib/libboost_regex.a
    ..../boost_1_61_0_b1/stage/lib/libboost_log_setup.a
    ..../boost_1_61_0_b1/stage/lib/libboost_thread.a
    ..../boost_1_61_0_b1/stage/lib/libboost_log.a
    ..../boost_1_61_0_b1/stage/lib/libboost_system.a
    ..../boost_1_61_0_b1/stage/lib/libboost_filesystem.a

The application compiles( after countless attempts). However, when I use ldd tool, it shows boost libraries on the dependency list.

Note: I have to define BOOST_ALL_DYN_LINK. Otherwise, it doesn't link.

Is there any way not to use this macro and overcome the dependency problem ? If not, what solutions do you suggest to circumvent this problem?

D.Badawi
  • 175
  • 1
  • 13

1 Answers1

2

By default on modern UNIX-like systems gcc links with shared libraries by default. In order to force static linking you can either add -static to your linking command line (see the docs) or make sure gcc doesn't find the shared libraries but only finds the static libraries (e.g. move the shared libraries to a separate directory while you're linking your project). Note that -static will make all libraries linked statically, including libstdc++.

Alternatively, you can specify the static libraries directly, without the -l switch. You will have to use the full path to the libraries though, so instead of

gcc ... -lboost_log ...

you would write

gcc ... ..../boost_1_61_0_b1/stage/lib/libboost_log.a ...

In any case, you should not define BOOST_ALL_DYN_LINK because this macro means exactly the opposite - that you intend to link with Boost shared libraries.

Andrey Semashev
  • 10,046
  • 1
  • 17
  • 27
  • I tried bjam -static then I linked to the .a libraries and It worked. I don't know if it's a Qt .pro problem or what but it seems that when there were both .a and .so libraries in the same path, it links to the .so even if it's specified otherwise. Thanks anyways – D.Badawi Jun 21 '16 at 12:35