Unsolved Undefined reference to boost libraries
-
Hello,
I am trying to run a QT project on Windows that I have developed on Linux Ubuntu. Unfortunately, I cannot manage it to properly link the boost library. Here is a detailed description of the problem.
I downloaded MinGW from https://nuwen.net/mingw.html, version 13.5, such that the gcc version 5.3.0 matches the MinGW version of QT. The reason to choose this version of MinGW is that it contains the boost libraries for compression such as zlib. From the command line I compile and run my program without any problems:
g++ -std=c++11 -w -IC:/MinGW/include -LC:/MinGW/lib bAya.cpp A.o B.o C.o -o baya -lboost_iostreams -lz -lbz2
where A,B, C are my pre-compiled object files.
In QT creator I selected the MinGW compiler (C:\MinGW_53\MinGW\bin\g++.exe) and created a new default with the compiler.
My .pro file looks as follows:
MAKE_CXXFLAGS += -std=c++11 INCLUDEPATH += C:/MinGW_53/MinGW/include \ C:/Users/kutzk/Documents/src LIBS += -LC:/MinGW_53/MinGW/lib/mylib \ -lboost_system \ -lboost_iostreams \ -lz \ -lbz2 greaterThan(QT_MAJOR_VERSION, 4): QT += widgets SOURCES += main.cpp\ mainwindow.cpp \ ../src/A.cpp \ ../src/B.cpp \ ../src/C.cpp HEADERS += mainwindow.h \ ../src/A.h \ ../src/B.h \ ../src/C.h
C:/MinGW_53/MinGW/lib/mylib contains my .a files such as libboost_iostreams.a
When I build it, I get many undefined reference errors such as
error: undefined reference to `boost::iostreams::zlib::default_strategy'Interestingly, if C:/MinGW_53/MinGW/lib/mylib contains also libstdc++.a I also get linking errors to std::cout, std::ifstream etc.
I am currently stuck and I will be very helpful for any feedback.
Best,
Konstantin[Edit: Added code formatting tags ~kshegunov]
-
Hello,
Try adding a
PRE_TARGETDEPS
list for your external static libraries, e.g.:PRE_TARGETDEPS += C:/MinGW_53/MinGW/lib/mylib/libboost_iostreams.a \ C:/MinGW_53/MinGW/lib/mylib/libboost_system.a \
Also substitute this
MAKE_CXXFLAGS += -std=c++11
with:CONFIG += c++11
Interestingly, if C:/MinGW_53/MinGW/lib/mylib contains also libstdc++.a I also get linking errors to std::cout, std::ifstream etc.
Why would it contain the standard library at all?
Kind regards.
-
Thank you for the reply.
At the end I was able to resolve the problem. Here is what I did. I am using QT 5.7 on Windows 10.-
I compiled boost using QT's console as described here: http://cpp-qt-mac-win.blogspot.co.uk/2011/10/qt-boost-for-beginners-step-by-step.html
-
Then I created a new project and added the paths to boost and the necessary libraries, as described in my question.
An important note. I tried to update the paths in the existing project, by running qmake and then rebuilding the project. I was getting the very same errors as I was getting with the old paths to "standard" boost. Apparently, something was cached and the changes didn't do anything. However, if I give a wrong path to a library it complained. So, QT has very confusing behavior. If someone can explain it, it will be helpful.
-
-
@Koki
Hello,So, QT has very confusing behavior. If someone can explain it, it will be helpful.
Qt (with small t) is the library. You're having problems with
qmake
the build system (also employed by Qt and QtCreator - the IDE). On windows sometimesqmake
is slow to pick up changes and might not "realize" it has to regenerate the makefile. Beside that I have nothing better as an explanation, since the information about the exact errors (undefined reference to is one of the most generic linker errors there is) and the events leading to them (what link line produced the errors, what symbols were referenced in the Qt project, what symbols were available from the boost binary, etc.) is somewhat scarce.In any case, I'm glad you were able to solve your problem.
Kind regards.