Add openssl/aes.h in Qt project - qt

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

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

Qt5 OpenCV3.4.5 LNK1105 cannot open opencv_world345d.obj

I am building a Qt5 project with OpenCV3.4.5 in windows. The OpenCV is a prebuilt version with opencv_world345.lib and opencv_world345dlib. I create a .pri file for including opencv into the Qt project. Here below is for the opencv .pri file:
INCLUDEPATH += C:/opencv-3.4.5/prebuild/include \
C:/opencv-3.4.5/prebuild/include/opencv \
C:/opencv-3.4.5/prebuild/include/opencv2
Debug: {
LIBS += lc:/opencv-3.4.5/prebuild/x64/vc14/lib/opencv_world345d
}
Release: {
LIBS += lc:/opencv-3.4.5/prebuild/x64/vc14/lib/opencv_world345
}
I also set C:\opencv-3.4.5\prebuild\x64\vc14\bin in the path of systems variables.
Building the project in debug mode gives the error: LINK : fatal error LNK1104: cannot open file 'lc:\opencv-3.4.5\prebuild\x64\vc14\lib\opencv_world345d.obj'.
What causes the error? Do I miss something else in configuring opencv for Qt?
Have you run qmake since making your changes to the .pri file?
Normally I would have asked for clarification in the comments, but I'm new to Stack Overflow and don't have 50 reputation yet.
EDIT:
I found an old project of mine that I have OpenCV3.1.0 properly linked to. Here's what I have in my .pro
LIBS += -L*PATH TO OPEN CV*/OpenCV-3.1.0/lib
INCLUDEPATH += *PATH TO OPEN CV*/OpenCV-3.1.0/include
CONFIG(release, debug|release):{
LIBS += \
-lopencv_world310
}
CONFIG(debug, debug|release):{
LIBS += \
-lopencv_world310d
}
Here below is the modified .pri file that works for me!
INCLUDEPATH += c:/opencv-3.4.5/prebuild/include
CONFIG(release, debug|release):{
LIBS += -L"c:/opencv-3.4.5/prebuild/x64/vc14/lib" -lopencv_world345
}
CONFIG(debug, debug|release):{
LIBS += -L"c:/opencv-3.4.5/prebuild/x64/vc14/lib" -lopencv_world345d
}
The configurations by Debug:{} and Release {} do not work!

qtcreator project file depndancies and build order

I am using qtcreator with subdir project structure. The case is that:
I have 2 projects. Project A and B. After A compiles, then B, but in B, I must use the headers of A (classes, functions, etc.). I`ve found in wiki the depends and subdir project setup, but when I try to include class A from project A into class B into project B ( these names are for convininece ) it gives me undefined referencies. Here is my .pro file from main project (and subprojects respectively ):
#base pro file
TEMPLATE = subdirs
SUBDIRS += \
message \
daemon \
receiver
daemon.subdir = daemon
message.subdir = message
daemon.depends = message
subproject A:
TEMPLATE = app
CONFIG += console c++11
CONFIG -= app_bundle
CONFIG -= qt
SOURCES += main.cpp \
daemon.cpp \
logwriter.cpp
HEADERS += \
daemon.h \
logwriter.h \
defs.h
LIBS += -lpthread
subproject B:
TEMPLATE = app
CONFIG += console c++11
CONFIG -= app_bundle
CONFIG -= qt
SOURCES += \
message.cpp \
main.cpp
HEADERS += \
message.h
So I need the project B classes into project A and further on when I extend the project.
Regards.
EDIT: A .pri example would be appreciated, if I'm going to set project A to be a library (-lclssA )
"undefined references" are generally link problems, not header include problems. You may have to link your project A with B if you need to use it.
e.g in A :
LIBS += ../path/to/libB.so
The simplest way is to include it as a lib, the easiest way was from qtcreator, rightclick on the dependee and "Add library" -> "Existing library from build tree". This will generate the following in the .pro:
win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../message/release/ -lmessage
else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../message/debug/ -lmessage
else:unix: LIBS += -L$$OUT_PWD/../message/ -lmessage
INCLUDEPATH += $$PWD/../message
DEPENDPATH += $$PWD/../message
However I am losing the ability to make tests for my message class in it's main class. So if there is a better way, I'd accept it.

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

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.

Importing Libraries into QTCreator

I am creating an OpenGL project in QT Creator, and would like to import GLFW and potentially other libraries later on.
I compiled and imported GLFW and was able to import it via
#include <GLFW/glfw3.h>
Qt Creator was even able to autofill the glfw methods. However, when I attempted to call one of them (e.g. glfwInit();, the compiler threw me the following error:
Undefined symbols for architecture x86_64:
"_CFArrayAppendValue", referenced from:
_addJoystickElement in libglfw3.a(iokit_joystick.m.o)
"_CFArrayApplyFunction", referenced from:
__glfwInitJoysticks in libglfw3.a(iokit_joystick.m.o)
_addJoystickElement in libglfw3.a(iokit_joystick.m.o)
"_CFArrayCreateMutable", referenced from:
... etc
I'm assuming it was unable to find the implementation of these methods.
I imported GLFW through the following procedure:
1. I used CMake to build a Unix Script. 2. I ran "make" in terminal on the generated makefile. This created a file called "libglfw3.a" 3. I imported the library into the project through QT, setting the Library as libglfw3.a and include path as "mypath/include/" (this folder contains another folder called GLFW, which contains glfw3.h).
QT Creator then entered the following into the QT project file.
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/glfw-3.1.1/src/release/ -lglfw3
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/glfw-3.1.1/src/debug/ -lglfw3
else:unix: LIBS += -L$$PWD/glfw-3.1.1/src/ -lglfw3
INCLUDEPATH += $$PWD/glfw-3.1.1/include
DEPENDPATH += $$PWD/glfw-3.1.1/include
win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/glfw-3.1.1/src/release/libglfw3.a
else:win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/glfw-3.1.1/src/debug/libglfw3.a
else:win32:!win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/glfw-3.1.1/src/release/glfw3.lib
else:win32:!win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/glfw-3.1.1/src/debug/glfw3.lib
else:unix: PRE_TARGETDEPS += $$PWD/glfw-3.1.1/src/libglfw3.a
Help would be greatly appreciated. I've spent at least 10 hours trying to figure out how to import a GL library into QT Creator, but all I can find are CMake tutorials for XCode, Visual Studio, etc.
I would ideally like to this by just modifying the QT .pro file, because I don't have experience with CMake, but if there are no alternatives, that's fine.
I'm developing with QT creator on Mac 10.10.15.
If anyone's curious, I figured it out.
I followed the procedure here: Compiling with GLFW3, linker errors 'undefined reference'
I didn't at first think this was relevant because it was specifically referring to building on XCode, but it turns out you have to do the exact same thing with QT Creator.
right click the project, Import Library -> System/Library/Frameworks -> and import Cocoa, CoreVideo, and IOKit.
My .pro file had the following lines added to them after I did all that
mac: LIBS += -framework Cocoa
else:unix|win32: LIBS += -lCocoa
mac: LIBS += -framework IOKit
else:unix|win32: LIBS += -lIOKit
mac: LIBS += -framework CoreVideo
else:unix|win32: LIBS += -lCoreVideo

Resources