How to link with Boost libraries in Qt Creator?
-
wrote on 25 Oct 2018, 12:05 last edited by franc
Hi all, I need to build a project using Qt Creator. This project needs to link with the static libraries
boost_system
andboost_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 theLIBS
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
, includingauto_link.hpp
in the code to link manually (and rebuild many times Boost libraries in the middle), but the system always tries to link withboost_system-vc120
, and notboost_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 (defineBOOST_ALL_NO_LIB
, expressingLIBS
, etc...).Any idea? Is it possible to show the environmental variables during the linking phase with Qt Creator?
-
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 doesBoost_USE_STATIC_LIBS
do ? Is it also a define ? -
wrote on 26 Oct 2018, 08:48 last edited by franc
Boost_USE_STATIC_LIBS
when it is set onON
, 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
andboost_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 inC:\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.
-
In the Run part of the Project panel, modify the
PATH
environment variable and addC:\Program Files\boost_1_55_0\stage\x86\lib
to it. -
In the Run part of the Project panel, modify the
PATH
environment variable and addC:\Program Files\boost_1_55_0\stage\x86\lib
to it.@SGaist FYI: Creator does this automatically if you specify
LIBS+=-L<path>
.
1/5