Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. How to link with Boost libraries in Qt Creator?
QtWS25 Last Chance

How to link with Boost libraries in Qt Creator?

Scheduled Pinned Locked Moved Unsolved Qt Creator and other tools
5 Posts 3 Posters 11.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    franc
    wrote on 25 Oct 2018, 12:05 last edited by franc
    #1

    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:

    DEFINES = BOOST_ALL_NO_LIB
    Boost_USE_STATIC_LIBS = ON
    win32 {
        DEFINES = BOOST_ALL_NO_LIB
        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 \
                -lboost_thread-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?

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 25 Oct 2018, 21:29 last edited by
      #2

      Hi,

      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 ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • F Offline
        F Offline
        franc
        wrote on 26 Oct 2018, 08:48 last edited by franc
        #3

        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 \
        

        with:

        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.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 26 Oct 2018, 21:12 last edited by
          #4

          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.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          A 1 Reply Last reply 28 Oct 2018, 16:56
          0
          • S SGaist
            26 Oct 2018, 21:12

            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.

            A Offline
            A Offline
            aha_1980
            Lifetime Qt Champion
            wrote on 28 Oct 2018, 16:56 last edited by
            #5

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

            Qt has to stay free or it will die.

            1 Reply Last reply
            2

            1/5

            25 Oct 2018, 12:05

            • Login

            • Login or register to search.
            1 out of 5
            • First post
              1/5
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved