Nominate our 2022 Qt Champions!

How to link with Boost libraries in Qt Creator?

  • Hi all, I need to build a project using Qt Creator. This project needs to link with the static libraries boost_system and boost_thread.

    I have compiled Boost libraries using Visual Studio 2015 (v.14.0), so that I have included the following lines to my .pro file:

    win32 {
        BOOSTHOME = C:/Boost
        INCLUDEPATH += C:/Boost/include/boost-1_55
        DEPENDPATH += C:/Boost/include/boost-1_55
        LIBS += -LC:/Boost/lib \
                -lboost_system-vc140-mt-gd-1_55 \
         !win32-g++: PRE_TARGETDEPS += C:/Boost/lib/boost_system-vc140-gd-1_55.lib
         !win32-g++: PRE_TARGETDEPS += C:/Boost/lib/boost_thread-vc140-mt-gd-1_55.lib

    The variable BOOST_ALL_NO_LIB should tell the system not to select automatically the linking libraries, which are explicitly expressed in the LIBS variable.

    During the linking phase, the following error occurs:

    error: LNK1104: cannot open file 'libboost_system-vc120-mt-gd-1_55.lib'

    which is very strange, since I have never installed Visual Studio 12.0 on this PC, and it should link with boost_system-vc140. I tried every suggestion found on other forums, like modifying auto_link.hpp, including auto_link.hpp in the code to link manually (and rebuild many times Boost libraries in the middle), but the system always tries to link with boost_system-vc120, and not boost_system-vc140.

    I write because at this point I am not totally sure whether I am using the .pro file in a proper way, and I do not know whether it follows what I state (define BOOST_ALL_NO_LIB, expressing LIBS, etc...).

    Any idea? Is it possible to show the environmental variables during the linking phase with Qt Creator?

  • Lifetime Qt Champion


    Did you check the content of the Makefile generated ?

    One thing that doesn't look correct is your DEFINES =, this nukes all values that might have been set before.
    What does Boost_USE_STATIC_LIBS do ? Is it also a define ?

  • Boost_USE_STATIC_LIBS when it is set on ON, should tell the linker to use the static version of the boost libraries.
    I have solved the issue: the problem was an incompatibility between architectures. I had to rebuilt boost libraries in X86 architecture instead of x64.

    Then, I have changed the line:

    LIBS += -LC:/Boost/lib \


    LIBS += -LC:\Program Files\boost_1_55_0\stage\x86\lib \

    but now I have another linker problem:

    LINK : fatal error LNK1104: cannot open file 'Files\boost_1_55_0\stage\x86\lib.obj'

    I think that the white space between "Program" and "Files" is causing some issues. I am trying to solve the problem, but if someone has already a solution it is well accepted!

    EDIT: I changed again the above line with:

    LIBS += -L"C:\Program Files\boost_1_55_0\stage\x86\lib" \

    It builds, but the program does not even start. The debugger returns the error message:

    The CBD process terminated.

    because the boost_thread-vc140-mt-gd-1_55.dll and boost_system-vc140-mt-gd-1_55 libraries cannot be found. It is very strange because I want to use static library. And, anyway, the problem should not be present because in C:\Program Files\boost_1_55_0\stage\x86\lib I do have both libraries (both .dll and .lib).

    EDIT: the problem has been solved rebooting the machine. I have never switched off my computer after having built the Boost libraries with x86 architecture. Windows is awesome.

  • Lifetime Qt Champion

    In the Run part of the Project panel, modify the PATH environment variable and add C:\Program Files\boost_1_55_0\stage\x86\lib to it.

  • Lifetime Qt Champion

    @SGaist FYI: Creator does this automatically if you specify LIBS+=-L<path>.

Log in to reply