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
Related
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
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.
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
I'm trying to add net-snmp lib to my project using win7 + cygwin:
Project file seems to contain valid lib and path entries:
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/C:/usr/lib/
-lnetsnmp else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/C:/usr/lib/ -lnetsnmpd
INCLUDEPATH += $$PWD/C:/usr/include DEPENDPATH += $$PWD/C:/usr/include
But I can't build the project, because include file is not found, also it exists under given directory physically (c:/usr/include/net-snmp/net-snmp-config.h)
../snmptest1221313123/main.cpp:1:38: fatal error: net-snmp/net-snmp-config.h: No such file or directory
#include
I've read all "add external lib" topics, but it doesn't help to solve this.
Re-running qmake, re-opening Qt creator, or running qmake -r from terminal doesn't help neither.
Remove $$PWD/ (both from include and libs) and try again: run qmake and rebuild.
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