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.