Qt error: undefined reference to 'QDebug::~QDebug()' - qt

I am compiling my code with caffe, opencv 3.1 and Qt5.6. Following is my .pro file. I have not included the actual source and header file names here.
QT += core gui network
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = outsideSituationDetection
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp \
<and others>
HEADERS += mainwindow.h \
< and others >
FORMS += mainwindow.ui
DEFINES += CPU_ONLY
QMAKE_CXXFLAGS += -std=c++11 -Wall -D_REENTRANT -D__STDC_CONSTANT_MACROS -pthread
QMAKE_CXXFLAGS += -DQT_COMPILING_QSTRING_COMPAT_CPP -DQT_COMPILING_QIMAGE_COMPAT_CPP
CONFIG += link_pkgconfig
PKGCONFIG += opencv
INCLUDEPATH += /usr/local/include /usr/local/lib /usr/lib
DEPENDPATH += /usr/local/include
LIBS += -L/usr/local/lib/ -lopencv_imgproc
LIBS += -lm -lglib-2.0 -lgthread-2.0 -lxml2 -pthread
INCLUDEPATH += /usr/include/glib-2.0
INCLUDEPATH += /usr/lib/x86_64-linux-gnu/glib-2.0/include
INCLUDEPATH += /usr/include/libxml2
INCLUDEPATH += /usr/include/ \
/usr/lib/x86_64-linux-gnu/ \
LIBS += -L/usr/lib/x86_64-linux-gnu/ -lglog -lpthread -lm -lrt -ldl -lnsl
DEPENDPATH += /usr/lib/x86_64-linux-gnu/
# BOOST Library
LIBS += -L/usr/lib/x86_64-linux-gnu/ -lboost_system
INCLUDEPATH += /usr/lib/x86_64-linux-gnu
#Caffe for CPU System
INCLUDEPATH += $$PWD/../../../../../src/caffe/build/include \
$$PWD/../../../../../src/caffe/include \
$$PWD/../../../../../src/caffe/build
unix:!macx: LIBS += -L$$PWD/../../../../../src/caffe/build/lib/ -lcaffe -lglog
INCLUDEPATH += $$PWD/../../../../../src/caffe/build
DEPENDPATH += $$PWD/../../../../../src/caffe/build
RESOURCES += icons.qrc
Problem - When I compile the code, I get a bunch of 'error: undefined reference to 'QDebug::~QDebug()'' errors along with 'error: undefined reference to `QDebug::putString(QChar const*, unsigned long)'' against all of my .cpp files. (I have successfully built and executed another application without errors using Qt5.6 and Qt5.7.)
(.qtversion[qt_version_tag]+0x0):-1: error: undefined reference to `qt_version_tag' File not found (.qtversion[qt_version_tag]+0x0) in main.o
What I have tried - Check Qt version to make sure I am using Qt5.6. Deleted the installed qt5-default by doing 'sudo apt-get remove qt5-default'. Downgraded from Qt5.7 to Qt5.6 although it didn't make any difference. I have deleted qt4 and qt5 folders from /usr/include and /usr/share.
Can you please suggest what I might be missing?

I had multiple declarations of ' #include "QDebug" ' in files. Removing them and having it in only one file removed the error. (edit- it's incorrect and doesn't work)
What worked - Though I had removed older versions of Qt 3, 4 & 5 , qt was internally using 5.2.1 versions. I do not know where they came from. But when I deleted them all in /usr/lib/x86_linux_gnu/, the code compiled! I also specified the paths to the installed directory explicitly in qtchooser/default.conf. This may not be the best way to do but it worked anyway.

Related

How to use value of environment variable in project file?

I'm trying to add a homebrew library to another project.
Following a suggestion in another answer that I now cannot find, I have created xyz.prf in mkspecs/features and have added
config += xyz
to my project file.
xyz.prf contains
INCLUDEPATH += $XYZ_INC
DEPENDPATH += $XYZ_INC
win32:CONFIG(release, debug|release): LIBS += -L$XYZ_DIR -llibxyz
else:win32:CONFIG(debug, debug|release): LIBS += -L$XYZ_DIR -llibxyz
else:unix: LIBS += -L$XYZ_DIR -llibxyz
I've defined XYZ_INC and XYZ_DIR in the build configuration and have run qmake as often as needed.
However, when I try to build, there's an error at link time.
g++ -Wl,-rpath,/opt/Qt/5.12.5/gcc_64/lib -o someprogram someprogram.o -L/home/alan/work/myStuff/sqlPrettyPrinter/v3/build-SQLPPv3-Desktop_Qt_5_12_5_GCC_64bit-Debug/test/test_collationname/../../libsqlpp/ -llibsqlpp -LYZ_DIR -llibxyz /opt/Qt/5.12.5/gcc_64/lib/libQt5Test.so /opt/Qt/5.12.5/gcc_64/lib/libQt5Core.so -lpthread
/usr/bin/ld: cannot find -llibxyz
Now, looking at the g++ command line, I see -LYZ_DIR which explains why ld can't find libxyz - it ought to be -L$XYZ_DIR or -L<whatever XYZ_DIR expands to>.
I've tried every combination of $ or $$ and XYZ_DIR, {XYZ_DIR} or (XYZ_DIR). None work and all but the above combination end up generating `-L' (without any directory).
What's the right syntax to generate what I need?
Sorry - this question has ended up longer than intended; however, I can't think of a way that it can sensibly be shortened.
As the docs points out, $$(...) must be used to obtain the environment variables:
Variables can be used to store the contents of environment variables. These can be evaluated at the time when qmake is run, or included in the generated Makefile for evaluation when the project is built.
To obtain the contents of an environment value when qmake is run, use
the $$(...) operator:
DESTDIR = $$(PWD)
message(The project will be installed in $$DESTDIR)
xyz.prf
INCLUDEPATH += $$(XYZ_INC)
DEPENDPATH += $$(XYZ_INC)
win32:CONFIG(release, debug|release): LIBS += -L$$(XYZ_DIR) -llibxyz
else:win32:CONFIG(debug, debug|release): LIBS += -L$$(XYZ_DIR) -llibxyz
else:unix: LIBS += -L$$(XYZ_DIR) -llibxyz
With the previous code element it is applied only when qmake is executed, but if you want it to be executed with the make command you must use $(...) as indicated by the docs:
To obtain the contents of an environment value at the time when the
generated Makefile is processed, use the $(...) operator:
DESTDIR = $$(PWD)
message(The project will be installed in $$DESTDIR)
DESTDIR = $(PWD)
message(The project will be installed in the value of PWD)
message(when the Makefile is processed.)
xyz.prf
INCLUDEPATH += $(XYZ_INC)
DEPENDPATH += $(XYZ_INC)
win32:CONFIG(release, debug|release): LIBS += -L$(XYZ_DIR) -llibxyz
else:win32:CONFIG(debug, debug|release): LIBS += -L$(XYZ_DIR) -llibxyz
else:unix: LIBS += -L$(XYZ_DIR) -llibxyz

Why doesn't qmake include library files?

I am trying to link a third party library to my Qt project. Here is my .pro file:
TEMPLATE = app
TARGET = camera_ui
QMAKE_LFLAGS += -Wl --enable-new-dtags -Wl -rpath /opt/pylon5/lib64
INCLUDEPATH += -I/opt/pylon5/include
LIBS += -L/opt/pylon5/lib64 -Wl -E \
-lpylonbase \
-lpylonutility \
-lGenApi_gcc_v3_0_Basler_pylon_v5_0 \
-lGCBase_gcc_v3_0_Basler_pylon_v5_0 \
-lopencv_core \
-lopencv_highgui
# Input
HEADERS += basler_opencv_utils.h camera_interface.h mainwindow.h
FORMS += mainwindow.ui
SOURCES += basler_opencv_utils.cc main.cpp mainwindow.cpp
But here is the output after running qmake then make.
g++ -c -m64 -pipe -O2 -Wall -W -D_REENTRANT -fPIC -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I. -I-I/opt/pylon5/include -isystem /usr/include/x86_64-linux-gnu/qt5 -isystem /usr/include/x86_64-linux-gnu/qt5/QtGui -isystem /usr/include/x86_64-linux-gnu/qt5/QtCore -I. -I/usr/lib/x86_64-linux-gnu/qt5/mkspecs/linux-g++-64 -o basler_opencv_utils.o basler_opencv_utils.cc
basler_opencv_utils.cc:5:33: fatal error: pylon/PylonIncludes.h: No such file or directory
compilation terminated.
Makefile:373: recipe for target 'basler_opencv_utils.o' failed
make: *** [basler_opencv_utils.o] Error 1
Notice that the INCLUDE_PATH works, but the LIBS and QMAKE_LFLAGS are not included in the build command. I've looked at this and this but those didn't solve my problem. I've also tried adding TARGETDEPS += libpylonbase.so as per this question, with no change.
I also tried using Qt Creator to make the .pro file for my, but I couldn't figure out what I was supposed to enter into the wizard in the "library files" field.
UPDATE: I was able to get it working with some help from the section below. If anyone else is trying to use the Basler Pylon SDK with QT5 here is a working make file (includes OpenCV as well).
QT += core gui widgets
TEMPLATE = app
TARGET = camera_ui
PYLON_ROOT = /opt/pylon5
# Input
HEADERS += basler_opencv_utils.h camera_interface.h mainwindow.h
FORMS += mainwindow.ui
SOURCES += basler_opencv_utils.cc main.cpp mainwindow.cpp
QMAKE_CPPFLAGS += /opt/pylon5/include
QMAKE_CXXFLAGS += -Wno-unknown-pragmas -Wno-unused-parameter -Wno-unused-variable
QMAKE_LFLAGS_RPATH += -Wl,--enable-new-dtags -Wl,-rpath,/opt/pylon5/lib64
INCLUDEPATH += /opt/pylon5/include
INCLUDEPATH += /opt/pylon5/lib64
LIBS += /opt/pylon5/lib64 -Wl,-E -lpylonbase -lpylonutility -lGenApi_gcc_v3_0_Basler_pylon_v5_0 -lGCBase_gcc_v3_0_Basler_pylon_v5_0
LIBS += -lopencv_core -lopencv_highgui
No, your INCLUDEPATH doesn't work. Your include is INCLUDEPATH += -I/opt/pylon5/include which resolves to -I-I/opt/pylon5/include correct (-I/opt/pylon5/include) and that is an invalid directory. -I must be removed from INCLUDEPATH. The header file PylonIncludes.h is expected to be in/opt/pylon5/include/pylon/PylonIncludes.h
The correct path to include a library is
LIBS += -L"/home/directory" -lmylibrary -mylibrary2 - If the library is not found, the compiler throws an error.
LIBS += -L/opt/pylon5/lib64 -Wl -E \ is invalid and truncates probably the libraries after -WL -E \
You linker flags: QMAKE_LDFLAGS is correct. QMAKE_LFLAGS += -Wl etc. Why you don't see it in the g++ command line? It's the compiler not the linker, you error out before.

Add openssl/aes.h in Qt project

I have a custom library I've called libdblib.a that I'm using on several projects, and this time I would like to use it in a Qt Project.
So I've added this library as an external library through Qt Creator, so far so good.
Thing is, my library needs openSSl support (especially aes functions), and I don't understand how to add it in the project.
I've already checked this website : http://doc.qt.io/qt-5/opensslsupport.html but it seems to concern Android stuff, so I don't feel it will help
Obviously, I have the necessary ssl libraries on my computer, I'm just trying to understand how to add it in my Qt Project.
Sorry if it's an "easy question", but I'm still figuring out Qt mechanics.
I'm here if you have more questions, so far my .pro looks like this :
QT += core gui network printsupport \
sql
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
#qtHaveModule(printsupport): QT += printsupport
TARGET = myTarget
TEMPLATE = app
CONFIG += warn_off
SOURCES += \
/* list of my sources */
HEADERS += \
/* list of my headers */
/* I'm guessing I have to add something here to make ssl work... */
LIBS += -lsqlite3 \
-L/usr/local/lib \
-lxml2
CONFIG += c++11
/* the following has been added by Qt creator when I imported my external lib */
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/Utils/release/ -ldblib
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/Utils/debug/ -ldblib
else:unix: LIBS += -L$$PWD/Utils/ -ldblib
INCLUDEPATH += $$PWD/Utils
DEPENDPATH += $$PWD/Utils
win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/Utils/release/libdblib.a
else:win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/Utils/debug/libdblib.a
else:win32:!win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/Utils/release/dblib.lib
else:win32:!win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/Utils/debug/dblib.lib
else:unix: PRE_TARGETDEPS += $$PWD/Utils/libdblib.a

Qt: cannot find DLLs even if I specify their location

I cannot understand why this Qt pro file does not work:
QT += core
QT += gui
TARGET = PrjName
CONFIG += qt
CONFIG += console
TEMPLATE = app
INCLUDEPATH += C:/Qt/4.8.4/include/Qt
QMAKE_LIBDIR += C:/Qt/4.8.4/bin
LIBS += -lQtCore4
LIBS += -lQtGui4
SOURCES += ...
HEADERS += ...
These are the linker errors:
error: cannot find -lQtGui
error: cannot find -lQtCore
The C:\Qt\4.8.4\bin directory exists, and the DLLs are there.
Thank you.
Platform: Windows 7, MinGW, Qt 4.8.4, QtCreator 2.8.0

Wt with Qt, .pro settings

I am trying to get Wt working with Qt. I have installed 1.47 boost library, compiled Wt (3.2.1) under Windows using cmake 2.8.8. Tired simple hello world but doesn't compile, getting undefined reference errors for example:
undefined reference to `Wt::WApplication::WApplication(Wt::WEnvironment const&, Wt::WtLibVersion)'
Here is my .pro file:
QT -= core
QT -= gui
INCLUDEPATH += ../../../lib/Wt/include \
../../../lib/boost_1_47 \
../../../lib/Wt/src
LIBS += -L../../../lib/Wt/lib \
-L../../../lib/boost_1_47/lib
win32:LIBS += -lwthttpd -lwtd -lboost_regex-vc100-mt-1_47
TARGET = HttpServerWt
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
This is the program I am trying to compile:
http://www.webtoolkit.eu/wt/src/hello
Probably, your WT libraries will be added to /usr/loca/lib by default. so specify link libraries accordingly[after checking whether its present there, else check in /usr/lib and include accordingly].
Set LIBS Variable as follows
LIBS += -L/usr/local/lib -lwtd -lwthttpd -lboost_regex-vc100-mt-1_47
I don't see any Problem in setting the INCLUDEPATH variable in your post.
And also make sure that you are adding the module corresponding to Wt::WApplication::WApplication(Wt::WEnvironment const&, Wt::WtLibVersion) in LIBS Variable.
For more look here.
I think you need more libraries, because in Ubuntu you need to add more than two libraries to compile a wt code with qt creator.
Here is my *.pro file
QT += core
QT -= gui
TARGET = prueba3
LIBS += -L/usr/lib -lwt -lwthttp -I/usr/local/include
LIBS += -L/usr/local/lib -lwthttp -lwt -lboost_regex -lboost_signals
LIBS += -lboost_system -lboost_thread -lboost_filesystem -lboost_date_time
#QMAKE_CXXFLAGS += -DNDEBUG
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
and it compiles/Build great, finally you must add this line to run settings(ctrl+5)
--docroot . --http-address 0.0.0.0 --http-port 9090

Resources