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.
Related
Im trying to compile the openNN Project with Qt.
Im using qt precompiled mingw32 for windows and the last opennn 3.1 projekt sources.
Opennn comes already with .pro Project files for direct use with qt creator/qmake.
However when i try to compile it i get the following errors:
D:/Projekte/opennn_build/opennn/release\libopennn.a(testing_analysis.o):testing_analysis.cpp:(.text+0xfc): undefined reference to `omp_get_num_threads'
D:/Projekte/opennn_build/opennn/release\libopennn.a(testing_analysis.o):testing_analysis.cpp:(.text+0x103): undefined reference to `omp_get_thread_num'
D:/Projekte/opennn_build/opennn/release\libopennn.a(testing_analysis.o):testing_analysis.cpp:(.text+0x22f): undefined reference to `GOMP_loop_dynamic_start'
D:/Projekte/opennn_build/opennn/release\libopennn.a(testing_analysis.o):testing_analysis.cpp:(.text+0x3d3): undefined reference to `GOMP_loop_dynamic_next'
D:/Projekte/opennn_build/opennn/release\libopennn.a(testing_analysis.o):testing_analysis.cpp:(.text+0x3e0): undefined reference to `GOMP_loop_end_nowait'
D:/Projekte/opennn_build/opennn/release\libopennn.a(testing_analysis.o):testing_analysis.cpp:(.text+0x64b): undefined reference to `GOMP_loop_dynamic_start'
it seems to be connected to openmp, however the *.pro files of opennn already contain the always suggested lines:
QMAKE_CXXFLAGS+= -fopenmp
QMAKE_LFLAGS += -fopenmp
trying to add the following didnt help either
LIBS+= -fopenmp
i need to make it work with qt, because i wanted to add it to an already existing qt project later.
solution:
edit in openn/tests/tests.pro
and the "exampletitle".pro file of each example in openn/examples/"exampletitle"/
change:
win32-g++{
QMAKE_LFLAGS += -static-libgcc
QMAKE_LFLAGS += -static-libstdc++
QMAKE_LFLAGS += -static
}
to
win32-g++{
QMAKE_LFLAGS += -static-libgcc
QMAKE_LFLAGS += -static-libstdc++
QMAKE_LFLAGS += -static
LIBS += -fopenmp
}
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 getting an error when trying to link a static boost_filesystem library with QMake.
I know that my boost install is working, because I can link to it no problem outside of QMake like this:
g++ -o my_file my_file.cpp -IC:\boost_1_55_0\boost_1_55_0 -LC:\boost_1_55_0\boost_1_55_0\stage\lib -lboost_system -lboost_filesystem
I tried linking Qt with boost_filesystem like this at first, but it seems that it could not find the libraries:
LIBS += -LC:\boost_1_55_0\boost_1_55_0\stage\lib -lboost_system -lboost_filesystem
"-lboost_system not found -lboost_filesystem not found"
I read something about how you need to specify absolute paths to static libs when using QMake, so I've changes my LIBS line in my .pro to the following:
LIBS += "C:\boost_1_55_0\boost_1_55_0\stage\lib\libboost_system-mgw48-mt-1_55.a" \
"C:\boost_1_55_0\boost_1_55_0\stage\lib\libboost_filesystem-mgw48-mt-1_55.a"
The libraries are found with this method, however I get the following error message:
undefined reference to boost::system::generic_category()
I was under the impression that this error only happen when boost_system isn't linked! I seems like it is linked though, because it finds the proper library for it, and I know my install of boost is good because the same library links fine (with the same compiler) outside of Qt Creator.
Here's the include in mainwindow.h:
include <boost/filesystem.hpp>
Here the full .pro:
QT += core gui
QT += network
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
QMAKE_CXXFLAGS += -std=c++11
TARGET = Downloader
TEMPLATE = app
INCLUDEPATH += C:\boost_1_55_0\boost_1_55_0
LIBS += "C:\boost_1_55_0\boost_1_55_0\stage\lib\libboost_system-mgw48-mt-1_55.a" \
"C:\boost_1_55_0\boost_1_55_0\stage\lib\libboost_filesystem-mgw48-mt-1_55.a"
SOURCES += main.cpp\
mainwindow.cpp\
rar_process.cpp\
HEADERS += mainwindow.h\
rar_process.h\
FORMS += mainwindow.ui
RESOURCES += \
graphics.qrc
And here's the full compiler output:
C:\Qt\Qt5.1.1\5.1.1\mingw48_32\bin\qmake.exe -spec win32-g++ -o Makefile ..\qt- downloader\Downloader.pro
C:/Qt/Qt5.1.1/Tools/mingw48_32/bin/mingw32-make -f Makefile.Release
mingw32-make[1]: Entering directory 'C:/Users/Patrick/Desktop/cpp/build-Downloader- Desktop_Qt_5_1_1_MinGW_32bit-Release'
g++ -Wl,-s -Wl,-subsystem,windows -mthreads -o release\Downloader.exe release/main.o release/mainwindow.o release/rar_process.o release/qrc_graphics.o release/moc_mainwindow.o release/moc_rar_process.o -lglu32 -lopengl32 -lgdi32 -luser32 -lmingw32 -lqtmain C:\boost_1_55_0\boost_1_55_0\stage\lib\libboost_system-mgw48-mt-1_55.a C:\boost_1_55_0\boost_1_55_0\stage\lib\libboost_filesystem-mgw48-mt-1_55.a - LC:\Qt\Qt5.1.1\5.1.1\mingw48_32\lib -lQt5Widgets -lQt5Network -lQt5Gui -lQt5Core
release/main.o:main.cpp:(.text.startup+0x1a): undefined reference to `boost::system::generic_category()'
release/main.o:main.cpp:(.text.startup+0x24): undefined reference to `boost::system::generic_category()'
Makefile.Release:86: recipe for target 'release\Downloader.exe' failed
c:/qt/qt5.1.1/tools/mingw48_32/bin/../lib/gcc/i686-w64-mingw32/4.8.0/../../../../i686- w64-mingw32/bin/ld.exe: release/main.o: bad reloc address 0x24 in section `.text.startup'
collect2.exe: error: ld returned 1 exit status
mingw32-make[1]: *** [release\Downloader.exe] Error 1
mingw32-make[1]: Leaving directory 'C:/Users/Patrick/Desktop/cpp/build-Downloader- Desktop_Qt_5_1_1_MinGW_32bit-Release'
makefile:34: recipe for target 'release' failed
GCC is very sensitive to the order in which you specify libraries during the linking stage. For example, if libA.a depends on libB.a and an executable App depends on both, then you'd have to invoke linker in the following way:
gcc main.o object1.o ... object2.o -lA -lB -o App
This implies that you have to change it to:
LIBS += "C:\boost_1_55_0\boost_1_55_0\stage\lib\libboost_filesystem-mgw48-mt-1_55.a" \
"C:\boost_1_55_0\boost_1_55_0\stage\lib\libboost_system-mgw48-mt-1_55.a"
To be cross-platform, it's recommended to make your build more robust:
Boost_VERSION = 1_55
COMPILER = mgw48
win32-g++* {
LIBS += $$(Boost_DIR)/stage/lib/libboost_filesystem-$${COMPILER}-mt-$${Boost_VERSION}.a \
$$(Boost_DIR)/stage/lib/libboost_system-$${COMPILER}-mt-$${Boost_VERSION}.a
PRE_TARGETDEPS += $$(Boost_DIR)/stage/lib/libboost_filesystem-$${COMPILER}-mt-$${Boost_VERSION}.a \
$$(Boost_DIR)/stage/lib/libboost_system-$${COMPILER}-mt-$${Boost_VERSION}.a
}
linux-g++* {
LIBS += -L$$(Boost_DIR)/stage/lib -lboost_filesystem-$${COMPILER}-mt-$${Boost_VERSION} \
-lboost_system-$${COMPILER}-mt-$${Boost_VERSION}
PRE_TARGETDEPS += $$(Boost_DIR)/stage/lib/libboost_filesystem-$${COMPILER}-mt-$${Boost_VERSION}.a \
$$(Boost_DIR)/stage/lib/libboost_system-$${COMPILER}-mt-$${Boost_VERSION}.a
}
NOTE: Boost_DIR would be treated as an environment variable here. So that you can flexibly build it on any system without hardcoding the system-dependent path to Boost. This is general practice in professional software development: try to hardcode as little as possible in your build system, whatever it is. Furthermore, it's reasonable to even make Boost_VERSION environment variable too. All you'd have to change then, are brackets to parentheses, i.e. $${Boost_VERSION} to $$(Boost_VERSION).
Finally, notice that I've used forward slash / as a path separator for both Windows and Linux. Backward slash \ is not only deprecated in QMake, but it is also discouraged in general. Once again, be cross-platform: simply let QMake handle the conversion.
Apparently boost-system will not link against mingw gcc 4.8.0 if it was built with mingw gcc 4.8.1.
I re-built boost with mingw gcc 4.8.0 and linked against those libs, and now it works!
I'm trying to compile a Qt Creator project on the command line. Here's what I did.
$ qmake
$ make
g++ -c -m64 -pipe -O2 -Wall -W -D_REENTRANT -DALLOWSYNCING -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I/usr/share/qt4/mkspecs/linux-g++-64 -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I. -o main.o main.cpp
In file included from ./model/videostream.h:4:0,
from ./model/videostreamersession.h:4,
from view/videoplayerwindow.h:4,
from main.cpp:3:
./model/videoframe.h:5:18: fatal error: QImage: No such file or directory
compilation terminated.
make: *** [main.o] Error 1
It looks like make can't find the header files for Qt-related classes. How do I tell make where it can find them using an additional parameter or environment variable? I noticed some search paths are included by default, but in my environment they're located in /opt/QtSDK/Desktop/Qt/474/gcc/include/.
As requested, my PRO file. It was initially generated by Qt Creator so it's nothing out of the ordinary.
QT += core gui
TARGET = output
TEMPLATE = app
SOURCES += # Trimmed for brevity
HEADERS += # Trimmed for brevity
# Special build flags
DEFINES += ALLOWSYNCING
# These libraries are required for the program to operate
LIBS += -ljrtp -ljthread
CXXFLAGS="-I/opt/QtSDK/Desktop/Qt/474/gcc/include/" CFLAGS="-I/opt/QtSDK/Desktop/Qt/474/gcc/include/" LDFLAGS="/opt/QtSDK/Desktop/Qt/474/gcc/lib" make
However, you're probably on a mac I'm guessing.. In which case you should just export QT_DIR=/opt/QtSDK/Desktop/Qt/474/, and add /opt/QtSDK/Desktop/Qt/474/bin to your PATH and that should jiggle everything into place once qmake runs.
This seems like it should be really simple. I compiled a library in Qt (this newmat library), and produced the file libnewmat.a. Now I need to integrate this library into another project but I just can't get it to work.
I've tried a few different things with the LIBS variable in my .pro file including:
Win32:LIBS += libnewmat.a #library is in same directory as the project
Win32:LIBS += "C:/...path.../libnewmat.a"
Win32:LIBS += L"C:/...path..." -lnewmat
I've even tried using forward and back slashes in the path but it made no difference. I also include this check to make sure the library is actually found:
!exists(libnewmat.a) {
error("libnewmat.a does not exist")
}
So I know that isn't the problem. What I don't understand is that when i ctrl+f the compiler output (which displays the commands that qmake is using at the command line), I don't find any reference to the library. For some reason my LIBS variable isn't making any difference on the command line which is where I would expect it to be. Here is a sample of the compiler output where I would expect the library to be referenced if anyone would like to double check:
g++ -c -g -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_OPENGL_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -I"..\..\..\..\Qt\2009.02\qt\include\QtCore" -I"..\..\..\..\Qt\2009.02\qt\include\QtGui" -I"..\..\..\..\Qt\2009.02\qt\include\QtOpenGL" -I"..\..\..\..\Qt\2009.02\qt\include" -I"..\Visual Studio Projects\NewMatProj\newmat10" -I"..\..\..\..\Qt\2009.02\qt\include\ActiveQt" -I"debug" -I"." -I"..\..\..\..\Qt\2009.02\qt\mkspecs\win32-g++" -o debug\moc_Window.o debug\moc_Window.cpp
g++ -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc -mthreads -Wl -Wl,-subsystem,windows -o debug\GLPractice.exe debug/main.o debug/GLWidget.o debug/Window.o debug/CGSWidget.o debug/moc_GLWidget.o debug/moc_Window.o -L"c:\Qt\2009.02\qt\lib" -lopengl32 -lglu32 -lgdi32 -luser32 -lmingw32 -lqtmaind -lQtOpenGLd4 -lQtGuid4 -lQtCored4
I suspect there is something really simple that I'm missing here.
I'm using QtCreator on Windows Vista.
I think the scope conditions are case sensitive:
win32:LIBS += libnewmat.a # lowercase w
I've the very same problem. Isn't it possible to link to a static library from a static library? Anyhow if you make a shared library by removing CONFIG+=static from .pro file you avoid this problem.
Cheers,
H
u dont need a lot of libs in pro file. try this, it worked for me.
Win32:INCLUDEPATH += .
Win32:LIBS += "C:/...path.../libnewmat.a"
or
Win32:DEPENDPATH += .
Win32:LIBS += "C:/...path.../libnewmat.a"
Also libnewmat.a might be linux library.. normally windows libs have .lib extension.. not sure though..
-Arps