Undefined reference to boost libraries in QT creator on Windows - c++

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 kit with the compiler.
My .pro file looks as follows:
MAKE_CXXFLAGS += -std=c++11
INCLUDEPATH += C:/MinGW_53/MinGW/include \
C:/Users/kuzk/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
The folder 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

Adding the library path for boost_iostreams:
-LC:/MinGW/lib \
after the line:
LIBS += -LC:/MinGW_53/MinGW/lib/mylib \
should fix it.

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.

Related

Cannot link realsense library on c++ on qt creator

I am trying basic C++ programs with Intel Realsense sdk2 with librealsense library on Qt Creator. My .pro file looks like the following
INCLUDEPATH += /home/magbot/opencv-3.4.8/build/include
LIBS += -L/home/magbot/opencv-3.4.8/build/lib \
-lopencv_core \
-lopencv_highgui \
-lopencv_imgcodecs \
LIBS += -L/usr/lib/x86_64-linux-gnu -lrealsense2 \
SOURCES += \
main.cpp
OpenCV libraries compile fine but the realsense library does not link. I get this error
error: cannot find -lrealsense2 . The folder /usr/lib/x86.... contains the file librealsense2.so but its in red. Please help...where am I doing it wrong
It seems that there is some error with your installation. I checked with Ubuntu 16.04 and 18.04. Both installation looks fine installed via package manager.
You should try reinstalling it. If you want to install it with package manager(apt-get) follow this
If you are installing from source code that follow this
As mention in comment by KamilCuk, you can also try to remove dead symbolic link and then create new one.
rm /usr/lib/x86.../librealsense2.so
ln -s /usr/lib/x86.../librealsense2.so.2.30 /usr/lib/x86.../librealsense2.so

Sha512 hash in QT via OpenSSL

I'm trying to use the Sha512 function in openSSL but can't seem to get it to work as I get compiler errors just starting into the code. I include #include <openssl/sha.h> at the top of the .cpp file, then in the action of a button event I put just the following code below.
SHA512_CTX ctx;
SHA512_Init(&ctx);
//Will uncomment below in later if I get SHA512_Init to work
//SHA512_Update(&ctx, string, strlen(string));
//SHA512_Final(digest, &ctx);
I get a linker error telling my undefined symbols for architecture x86_64, implying the function does not exist?
I'm aware QT 5 has a hash function, but I'm limited to QT 4.8 so I can not use the cryptographic sha512 hash function available in the QT 5+ framework.
Any help is appreciated!
Used macports to install openssl
I'm using Mac OS 10.9.2
MAKE FILE
#-------------------------------------------------
#
# Project created by QtCreator 2014-06-11T20:27:49
#
#-------------------------------------------------
QT += core gui network
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = ExchangeTab
TEMPLATE = app
LIBS += -L/usr/include/openssl -openssl
INCLUDEPATH += /usr/include/openssl
SOURCES += main.cpp\
mainwindow.cpp \
httpsocket.cpp \
cloaksend.cpp \
exchange.cpp
HEADERS += mainwindow.h \
httpsocket.h \
cloaksend.h \
exchange.h
FORMS += mainwindow.ui
RESOURCES += \
AppResources.qrc
Looking for cross platform solution please.
You need to link to the right library (openSSL)
Have a look here: How to Include OpenSSL in a Qt project
Specifically, add this to your .pro file.:
LIBS += -L/opt/local/lib/ -lcrypto
For including .h files add this line to your .pro file :
INCLUDEPATH += /opt/local/include
[1] says that the default include path will be /opt/local/include/.
LIBS += -L/usr/include/openssl -openssl
INCLUDEPATH += /usr/include/openssl
This looks incorrect. The OpenSSL libraries are libcrypto (-lcrypto) and libssl (-lssl). There is nolibopenssl(-lopenssl). Try:
LIBS += -L/usr/lib -lcrypto
INCLUDEPATH += /usr/include/openssl
But the libraries are version 0.9.8. You might consider upgrading to 1.0.1h.
$ ls /usr/lib | grep crypto
libcrypto.0.9.7.dylib
libcrypto.0.9.8.dylib
libcrypto.dylib
libk5crypto.dylib
And
$ /usr/bin/openssl version
OpenSSL 0.9.8y 5 Feb 2013
If you choose to upgrade, OpenSSL will install into /usr/local/ssl. Avoid mixing/matching version of OpenSSL with the following.
INCLUDEPATH += /usr/local/ssl/include/openssl
LIBS += /usr/local/ssl/lib/libcrypto.a
Its OK to specify objects and archives in LIBS. See How to add object files to a project in Qt.
Okay so I may have answered my own question but I will need some help understanding why it worked.
My make file was indeed the problem. I added the following 3 lines.
INCLUDEPATH += $$OPENSSL_INCLUDE_PATH
LIBS += $$join(OPENSSL_LIB_PATH,,-L,)
LIBS += -lcrypto
Then it magically compiled just fine. I found these in another project made with QT that compiled for OpenSSL.
Interestingly enough. I removed the top two lines so only the following remained. Then ran the clean on my project to be sure the code was being recompiled.
LIBS += -lcrypto
This also just 'worked' without linker errors. It looks like that is the only command I need. Question is... will that be cross platform friendly if I take this code and compile on linux or windows? That I am not sure, but this worked.

How do I integrate C++ Boost into a Qt project?

I would like to use boost/filesystem.hpp in my Qt app but the builder keeps saying:
Library not loaded: libboost_filesystem.dylib
Reason: image not found
here is how I try to link it:
INCLUDEPATH+= /installdir/boost_1_50_0
LIBS += -L/installdir/boost_1_50_0/stage/lib -lboost_filesystem
I've tried linking directly, too. I've also tried rebuilding boost according to jschoen's answer, no difference.
Im running a MacOSX Lion. How do I have to link boost properly?
In the meantime I have found a solution.
install boost with macports (sudo port install boost) Thanks to dies and Tim Cooper.
then link against:
INCLUDEPATH += /opt/local/include
LIBS += -L/opt/local/lib
LIBS += -lboost_system-mt -lboost_filesystem-mt

Linking freeglut with Qt Creator in Linux

I currently run Arch Linux on my laptop and was hoping to know why Qt Creator isn't finding my glut library (which exists on my system).
My setup qmake file looks as follows:
...
/*sources and headers above*/
QT += opengl
LIBS += -lfreeglut
INCLUDEPATH += -L/usr/lib/
And when I run a locate glut, I get the following:
/usr/include/kwinglutils.h
/usr/include/kwinglutils_funcs.h
/usr/include/GL/freeglut.h
/usr/include/GL/freeglut_ext.h
/usr/include/GL/freeglut_std.h
/usr/include/GL/glut.h
/usr/lib/libglut.a
/usr/lib/libglut.so
/usr/lib/libglut.so.3
/usr/lib/libglut.so.3.9.0
/usr/share/avogadro/fragments/amino_acids/D-glutamic_acid.cml
/usr/share/avogadro/fragments/amino_acids/D-glutamine.cml
/usr/share/avogadro/fragments/amino_acids/L-glutamic_acid.cml
/usr/share/avogadro/fragments/amino_acids/L-glutamine.cml
/usr/share/licenses/freeglut
/usr/share/licenses/freeglut/LICENSE
/var/lib/pacman/local/freeglut-2.6.0-1
/var/lib/pacman/local/freeglut-2.6.0-1/changelog
/var/lib/pacman/local/freeglut-2.6.0-1/desc
/var/lib/pacman/local/freeglut-2.6.0-1/files
Note that I have tried -lglut32 in my qmake file as well.
What could I be missing here?
When you specify -lfoobar in your .pro file (or with gcc in general), you're directing the compiler to search for the library libfoobar.a. Judging from your locate output it looks like you want:
LIBS += -lglut
Oh, silly me. I just realized that the correct lib to add was just -lglut and not -lglut32. This is because there exists libglut.so, and not libglut32.so.

QMake and wxWidgets (External Libraries)

I'm trying to compile a GUI program based on the wxWidgets libraries. I get a lot of undefined references to "something". I tried to add a few libraries manually on the LIBS variable of QMake without success. How can i add all the wxWidgets libraries to QMake without hard coding each library? Below is my .pro file.
# simple.pro
TARGET = sample
HEADERS += main.h simple.h
SOURCES += main.cpp simple.cpp
LIBS += -LC:/SourceCode/Libraries/wxWidgets2.8/lib/gcc_dll/wxmsw28_core_gcc.dll \
-LC:/SourceCode/Libraries/wxWidgets2.8/lib/gcc_dll/wxmsw28_gcc.dll \
-LC:/SourceCode/Libraries/wxWidgets2.8/lib/gcc_dll/wxmsw28_aui_gcc.dll
INCLUDEPATH += C:/SourceCode/Libraries/wxWidgets2.8/include
CONFIG += release
The errors are of the form:
release/simple.o:simple.cpp:(.rdata$_ZTV6Simple[vtable for
Simple]+0x320): undefined reference to
`wxFrameBase::SetStatusBar(wxStatusBar*)'
First, you need to use the .a files to add to the linker.
Then you need to define WXUSINGDLL if you link against the shared libraries.
Additionally, you forgot
wxbase29u.a
Hope that helps.