Qt: How can I add two different external library path? - c++

I am trying to add two different external library path on Qt. So I put INCLUDEPATH and LIBS below to .pro file;
INCLUDEPATH += C:/SiliconSoftware/Runtime5.4.0/include \
C:/Basler/pylon4/pylon/include
LIBS += -L"C:\SiliconSoftware\Runtime5.4.0\lib\visualc" \
-lclsersis \
-ldisplay_lib \
-lfglib5 \
-lgbelib \
-liolibrt \
-lsiso_auxport \
-lsiso_genicam
LIBS += -L"C:\Basler\pylon4\pylon\lib\Win32" \
-lPylonUsb_MD_VC100_TL \
-lPylonUtility_MD_VC100 \
-lPylon1394_MD_VC100_TL \
-lPylonBase_MD_VC100 \
-lPylonBootstrapper \
-lPylonCLSer_MD_VC100_TL \
-lPylonGigE_MD_VC100_TL \
-lPylonGUI_MD_VC100
But I got this error;
C:\Users\GitekVision\Documents\Qt Projects\PylonSetUp\pylonsetup.h:4: error: >C1083: Cannot open include file: 'pylon/PylonIncludes.h': No such file or >directory.
I tried to take libraries one by one, it works. But together not working.
Anyone knows how to use 2 different external library on Qt project?

Related

How linux and g++ understand what include path it needs to use?

I'm not quite completely understand how linux or g++ (gcc) define what include path it need to use to find some package. Here is what I mean:
I actually have a c++ project in QtCreator and I use qmake build system. I include in my code a header-only framework file, which needs a Boost of one of the last version. I have already in my system boost-1.64.0, but it's too old, so I've installed boost-1.80.0. But when I try to build the program a compilation error raises with the text:
{name_of_my_pro_file}.pro: rpm boost1.64.0-devel is not installed!!!
I thought if I just replace boost folder in /usr/include/ or /usr/local/include/ with folder of the newer boost version linux can use it instead of older one. But the error mentioned above still raises. I've tried to edit boost folder name in Makefile. Directly in my .pro file there is not any mentions about boost. But nothing helped me. I can handle it only when I renamed boost-1.80.0 folder to boost-1.64.0. And now it works.
It seems that name boost-1.64.0 is written somewhere in the system and it doesn't see any other packages.
I guess that I just don't understand how to work with this stuff correctly and doing something wrong. Can somebody explain what should I do?
My distro is Oracle Linux Server 8.4.
EDIT:
My .pro file:
QT += core gui network xml
QMAKE_CXXFLAGS += -std=c++0x
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = TilesDataProvider
TEMPLATE = app
#DESTDIR = ./output
DEFINES += QT_DEPRECATED_WARNINGS
DEFINES += QT_DEPRECATED_WARNINGS
CONFIG += no_abi_dump
INCLUDEPATH += \
$$PWD \
$$PWD\guts \
$$PWD\SRTM \
$$PWD\tileSources \
/usr/include
CONFIG(release, debug|release){
message(release)
TARGET = TilesDataProvider
OBJECTS_DIR = tmp/TilesDataProvider/release
MOC_DIR = tmp/TilesDataProvider/moc
}
CONFIG(debug, debug|release){
message(debug)
TARGET = TilesDataProvider_d
OBJECTS_DIR = tmp/TilesDataProvider/debug
MOC_DIR = tmp/TilesDataProvider/moc
DEFINES += _DEBUG
}
SOURCES += \
main.cpp \
tileSources/MapTileSource.cpp \
tileSources/SrtmTileSource.cpp \
guts/Position.cpp \
guts/t_task.cpp \
guts/MapConversions.cpp \
SRTM/altdatabank.cpp \
SRTM/altdatamap.cpp \
SRTM/geoid.cpp \
SRTM/srtm_coordinate.cpp \
SRTM/t_geodata.cpp \
SRTM/t_pageid.cpp \
t_image.cpp \
tilesdataprovider.cpp
HEADERS += \
tileSources/MapTileSource.h \
tileSources/SrtmTileSource.h \
guts/MapGraphics_global.h \
guts/Position.h \
guts/t_task.h \
guts/MapConversions.h \
SRTM/altdatabank.h \
SRTM/altdatamap.h \
SRTM/geoid.h \
SRTM/srtm_coordinate.h \
SRTM/t_geodata.h \
SRTM/t_pageid.h \
SRTM/tiff_param.h \
t_image.h \
tilesdataprovider.h

Unresolved symbols: Qt and OpenCV

I have been trying to use OpenCV in my Qt-based application. However, I am running into linking errors for some reason.
I am using Qt 5.5.0, MSVC 12.0, OpenCV 3.0, Windows 7. My OpenCV is unpacked in C:\opencv folder. I am not trying to compile the library myself, just using what came in the package. As shown in the code below, I am linking to libraries located in vc12 folder.
I have removed all my code and made it really basic for troubleshooting purposes, so I have a default starter QtWidget project (with an empty screen), to which I added a single line:
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <opencv2/core.hpp>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
cv::Mat M;
}
MainWindow::~MainWindow()
{
delete ui;
}
If I comment out the only openCV command (cv::Mat M;) the code compiles and runs. With this line present I am getting two unresolved symbol errors:
mainwindow.obj:-1: error: LNK2019: unresolved external symbol "void __cdecl cv::fastFree(void *)" (?fastFree#cv##YAXPEAX#Z) referenced in function "public: __cdecl cv::Mat::~Mat(void)" (??1Mat#cv##QEAA#XZ)
mainwindow.obj:-1: error: LNK2019: unresolved external symbol "public: void __cdecl cv::Mat::deallocate(void)" (?deallocate#Mat#cv##QEAAXXZ) referenced in function "public: void __cdecl cv::Mat::release(void)" (?release#Mat#cv##QEAAXXZ)
I have tried various ways to statically link openCV libraries, but I keep getting the same errors (I always clean, re-run QMake, and then re-build the project for every attempt). Here is what my .pro file looks like right now (I ended up adding all static libs hoping that would help - it did not):
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = Test
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
win32:CONFIG(release, debug|release): LIBS += -LC:/opencv/build/x86/vc12/staticlib \
-lopencv_core300 \
-lopencv_highgui300 \
-lopencv_imgproc300 \
-lIlmImf \
-lippicvmt \
-llibjasper \
-llibjpeg \
-llibpng \
-llibtiff \
-llibwebp \
-lopencv_calib3d300 \
-lopencv_features2d300 \
-lopencv_flann300 \
-lopencv_hal300 \
-lopencv_imgcodecs300 \
-lopencv_ml300 \
-lopencv_objdetect300 \
-lopencv_photo300 \
-lopencv_shape300 \
-lopencv_stitching300 \
-lopencv_superres300 \
-lopencv_ts300 \
-lopencv_video300 \
-lopencv_videoio300 \
-lopencv_videostab300 \
-lzlib
else:win32:CONFIG(debug, debug|release): LIBS += -LC:/opencv/build/x86/vc12/staticlib \
-lopencv_core300d \
-lopencv_highgui300d \
-lopencv_imgproc300d \
-lIlmImfd \
-lippicvmt \
-llibjasperd \
-llibjpegd \
-llibpngd \
-llibtiffd \
-llibwebpd \
-lopencv_calib3d300d \
-lopencv_features2d300d \
-lopencv_flann300d \
-lopencv_hal300d \
-lopencv_imgcodecs300d \
-lopencv_ml300d \
-lopencv_objdetect300d \
-lopencv_photo300d \
-lopencv_shape300d \
-lopencv_stitching300d \
-lopencv_superres300d \
-lopencv_ts300d \
-lopencv_video300d \
-lopencv_videoio300d \
-lopencv_videostab300d \
-lzlibd
INCLUDEPATH += C:/opencv/build/include/
DEPENDPATH += C:/opencv/build/include/
Is there something in particular I am missing about the configuration? I am pretty sure the basic syntax (like slashes, etc) is ok since I was able to link another library in Qt Creator in another project, but I will be more than happy to try any suggestions at this point.
So after searching around and multiple attempts I found out what was wrong. I was linking to x86 library instead of x64. If I changed to x64 libs, I was getting mismatch between Static and Dynamic linker directives. Linking OpenCV statically would not work since OpenCV libraries themselves link to libcmt.lib, whereas Qt (pre-built) links dynamically to the counter-part of libcmt.lib, i.e. to msvcrt.lib. And since these two MS libraries are one and the same (just one is for static linking, the other for dynamic), I had two options: either rebuild Qt or OpenCV (which I don't want to do - I am very new to this kind of issues), or link OpenCV dynamically.
I opted for the second option. All you have to do is to remove all references to /staticlib folder and libs that it contains, and replace it with the following:
win32:CONFIG(release, debug|release): LIBS += -LC:/opencv/build/x64/vc12/lib -lopencv_world300
else:win32:CONFIG(debug, debug|release): LIBS += -LC:/opencv/build/x64/vc12/lib -lopencv_world300d
Note that one has to distribute corresponding DLLs with the application (located in build\x64\vc12\bin\ folder).

Qt with opencv exception handling error

I have been able to successfully integrate opencv with Qt using the following tutorial:
How to link opencv in QtCreator and use Qt library
However, When I try to write line #include "opencv/cv.h in my .cpp file, qt throws me an error:
D:\opencv\opencv_bin\install\include\opencv2\flann\saving.h:113: error: exception handling disabled, use -fexceptions to enable
throw FLANNException("Invalid index file, cannot read");
^
I am not sure if this is a qt problem or an opencv installation problem.
TEMPLATE = app
TARGET = cube4
QT += 3d
SOURCES = cubeview.cpp main.cpp \
haptics.cpp
HEADERS = cubeview.h \
haptics.h \
src/haptics.h \
src/adll.h \
src/afuncs.h \
src/atypes.h \
src/avars.h \
src/glut.h \
src/StdAfx.h \
hdl/hdl.h \
hdl/hdlConstants.h \
hdl/hdlErrors.h \
hdl/hdlExports.h \
hdlu/hdlu.h \
hdlu/hdluExports.h
HEADERS += \
Widget.h
RESOURCES = cube.qrc
win32:LIBS += -LD:\\opencv\\opencv_bin\\bin \
libopencv_core248d \
libopencv_highgui248d \
libopencv_imgproc248d \
libopencv_features2d248d \
libopencv_calib3d248d \
win32: INCLUDEPATH +="D:/opencv/opencv_bin/install/include"
Thanks iHarob. The solution was to add "exceptions" to the CONFIG variable in your project file (the *.pro file):
CONFIG += exceptions
This takes care of passing the correct compiler flags. The answer can be found here:
How to enable exception handling in mingw

Use KDSoap in C++

i try to create a client for a soap service in c++, i try with kdsoap, i build and install easily, but i can't get use in my projects
I create the .pro file with qmake -project, and only add the next line
include ( kiosco-touch.pri )
In their file, i put this content
INCLUDEPATH += \
/home/user/proyects/KDSoap/src \
/home/user/proyects/KDSoap/src/KDSoapClient \
/home/user/proyects/KDSoap/src/KDSoapServer
DEPENDPATH += \
/home/user/proyects/KDSoap/src \
/home/user/proyects/KDSoap/src/KDSoapClient \
/home/user/proyects/KDSoap/KDSoapServer
LIBS += -L/home/user/proyects/KDSoap/lib -l/home/user/proyects/KDSoap/
!isEmpty(QMAKE_LFLAGS_RPATH):LIBS += $$QMAKE_LFLAGS_RPATH/home/user/proyects/KDSoap/lib
include(/home/user/proyects/KDSoap/variables.pri)
DEFINES -= QT_NO_CAST_FROM_ASCII
When i execute qmake and make, i don't get any error of compilation, but says something
"/usr/bin/ld: can not open out file, /bin/kiosco-touch: denied permission”
Redading the Makefile generated, say this
QMAKE_TARGET = kiosco-touch
DESTDIR = /bin/#avoid trailing-slash linebreak
TARGET = /bin/kiosco-touch
For one reason, try create executable file with bin.
So i will edit the .pro or .pri files for read and create correctly the executable, someone have example with this library, or knows how i will read the libraries.
Well, i update the post, finally i can get with work, change the .pri file and now content this.
LIBS += -L/home/user/proyects/KDSoap/lib -lkdsoap
INCLUDEPATH += \
/home/user/proyects/KDSoap/include \
/home/user/proyects/KDSoap/src \
/home/user/proyects/KDSoap/src/KDSoapClient \
/home/user/proyects/KDSoap/src/KDSoapServer
DEPENDPATH += \
/home/user/proyects/KDSoap/src \
/home/user/proyects/KDSoap/include \
/home/user/proyects/KDSoap/src/KDSoapClient \
/home/user/proyects/KDSoap/src/KDSoapServer
And too is necessary create enviroment variable $LD_LIBRARY_PATH as is described by the installation manual.

Avoid duplicate object files using subdir structure with qmake

I have a game with two separate projects for the application itself and the tests. I'm building all of the projects in-source. Here's a shortened version of my project structure:
game
game.pro
app
app.pro
Entity.h
Entity.cpp
Entity.o
moc_Entity.cpp
moc_Entity.o
tests
layer
layer.pro
Entity.o (duplicated)
moc_Entity.cpp (duplicated)
moc_Entity.o (duplicated)
tst_Layer.cpp
app.pro:
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4) {
QT += widgets
}
TARGET = cotw-clone
TEMPLATE = app
MOC_DIR = .moc
OBJECTS_DIR = .obj
HEADERS += MainWindow.h \
Map.h \
Tile.h \
Character.h \
Layer.h \
NewGameDialog.h \
GameController.h \
Stair.h \
Random.h \
MapGenerator.h \
TileData.h \
Statistics.h \
StatisticsDialog.h \
StatisticWidget.h \
Range.h \
Level.h \
RandomMapGenerator.h \
AiController.h \
MonsterJournalWidget.h \
InventoryDialog.h \
PathSearch.h \
PathNode.h \
Path.h \
Geometry.h \
EntityDatabase.h \
EntityData.h \
Entity.h \
CharacterData.h \
EntityMetadata.h
SOURCES +=\
MainWindow.cpp \
Map.cpp \
Tile.cpp \
Character.cpp \
Layer.cpp \
NewGameDialog.cpp \
GameController.cpp \
Stair.cpp \
TileData.cpp \
Statistics.cpp \
StatisticsDialog.cpp \
StatisticWidget.cpp \
Level.cpp \
RandomMapGenerator.cpp \
AiController.cpp \
MonsterJournalWidget.cpp \
InventoryDialog.cpp \
PathSearch.cpp \
PathNode.cpp \
Path.cpp \
EntityDatabase.cpp \
EntityData.cpp \
Entity.cpp \
CharacterData.cpp \
main.cpp
FORMS += MainWindow.ui \
NewGameDialog.ui \
StatisticsDialog.ui \
StatisticWidget.ui \
MonsterJournalWidget.ui \
InventoryDialog.ui
RESOURCES += \
icons/icons.qrc \
tiles/tiles.qrc
RESOURCES += \
entities/entities.qrc
My problem is that all of the tests projects use classes from the app project, which means they're compiling all of these classes even though they've already been compiled when app was built. Take the layer test project, for example:
layer.pro:
QT += testlib
QT -= gui
greaterThan(QT_MAJOR_VERSION, 4) {
QT += widgets
}
TARGET = tst_LayerTest
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += tst_LayerTest.cpp
DEFINES += SRCDIR=\\\"$$PWD/\\\"
HEADERS += "../../app/Entity.h"
SOURCES += "../../app/Entity.cpp"
So how can I point qmake to the .o (and qrc_, .moc etc.) files that have already been produced in app? Is there some qmake variable for this purpose, or is my project structure just fundamentally flawed?
You can use wildcards in qmake .pro files, to save having to maintain a list of all file names.
For example,
SOURCES += *.cpp
Each time you run qmake, that pattern *.cpp gets expanded in to the current list of files matching the pattern.
You can also use -= to remove file names, if you have a particular filename that you wish to exclude.
For example:
SOURCES += *.cpp
SOURCES -= main.cpp
Edit
I almost suggested in my earlier answer that you introduce a library, using qt's lib template, to contain your common code.
Then your build structure would look like this - assuming that you can move files around, from app/ to lib/:
game
game.pro
app
app.pro
main.cpp
lib
lib.pro
Entity.h
Entity.cpp
Entity.o
moc_Entity.cpp
moc_Entity.o
tests
layer
layer.pro
tst_Layer.cpp
You can find some info on library projects in "Building a Library" on the Qt website
If, for some reason, you can't move your files around, then you can introduce a new directory for the library, and have it pull in source files from the app directory - but that is definitely more faff, and more confusing:
game
game.pro
app
app.pro - builds only main.o
main.cpp
Entity.h
Entity.cpp
moc_Entity.cpp
lib
lib.pro
Entity.o
moc_Entity.o
tests
layer
layer.pro
tst_Layer.cpp
Edit 2
One problem you have is you are putting object files in to the LIBS variable, which defines what libraries your code will link against. So that'll be why you are getting errors with those files.
Try changing those LIBS uses to OBJECTS instead, and it may work.
If not, have a read of this thread, which is asking pretty much the same thing.
In particular, see the answer by ChrisW67 of '13th May 2012, 10:14' which begins;
Try:
OBJECTS += f1.o f2.o f3.o f3.o
although I think that, if you have the source, building it into your
app directly or via a library is a better option.