Qt Creator can't find missing libraries - c++

I have referenced the following libraries, but Qt Creator v3.0.1 can't seem to find them.
LIBS += -lueye_api \
-lcv \
-lhighgui
Is it that the libraries have been deprecated? Are there any replacements for these three libraries?
I've google searched my problem and found what may be a start. Is -lopencv_core a suitable replacement for -lcv and is -lopencv_highgui a suitable replacement for -lhighgui?

When the library the project refers to cannot be found in the same directory as .pro file it is practical to refer to other libraries somehow relative to project file directory.
LIBS += -L$$PWD/../third-party -lother
Where the project file directory is located relative to third-party like that:
../project
../third-party
and the other.lib is in:
../third-party/other.lib
Or you just need to provide the path to libraries you use somehow.

Related

Libharu explain link in QT c++

I download libharu.zip, try to include it into QT creator c++.
But I don't have lib*.a files in libharu. What do I need to do? It has some makefiles etc.
I find some info about makefile, but don`t understand how it works in QT creator.
nmake -f Makefile.win
What do I need to run this command?
You will need a .so or a .a for linking, in qt creator edit your .pro:
INCLUDEPATH += <path_to_lib>/your_lib_include
When you have a .so for linking:
LIBS += -L<path_to_lib> -l<libname>
When you have a .a for linking:
LIBS += <path_to_lib>/libname.a

opencv2/calib3d.hpp : No suh file or directory (How to link opencv to qt correcttly)

I installed opencv 3.4.0-dev and I want to use it with QT.
In the .pro I added :
LIBS += -L/usr/local/lib -lopencv_core -lopencv_imgcodecs -lopencv_highgui -lopencv_calib3d
INCLUDEPATH += /usr/local/include/opencv
but i still have the error
opencv2/calib3d.hpp : No such file or directory
(I also try with highgui, imgcedexs, core, same error)
Any idea to fix it ?
Thank you in advance.
As you've figured by yourself, the opencv header path is now nested in /usr/local/include/opencv4.
As for the error you've flagged in the comment, ximgproc is a contrib module and should be added manually. You therefore need to build OpenCV from source or find a pre-built package that has the contrib modules built in.
This question and this OpenCV doc page answers how to build OpenCV with the contrib modules.
I fixed it by installing following:
sudo apt install libopencv-calib3d-dev

How can I make OpenCV the default library for my qt projects?

Please suppose that I want to link OpenCV libraries in Qt-creator, in common, I will add headers usingINCLUDEPATH and link libraries using the LIBS variable, which is used in the qmake file but if we use OpenCV in most of our projects then we have to include OpenCV library every time, so is there any way to add opencv libraries automatically at the time of creating a project.
I use the below command to add OpenCV libraries for my projects every time.
INCLUDEPATH += -I/usr/local/include/opencv
LIBS += -L/usr/local/lib -lopencv_stitching -lopencv_superres ...and etc.
UPDATE
I will use the following headers for OpenCV4:
INCLUDEPATH += /usr/local/include/opencv4
1) You can create a .prf (project feature) file in your mkspecs/features directory:
/usr/share/qt5/mkspecs/features/opencv.prf
INCLUDEPATH += -I/usr/local/include/opencv
LIBS += -L/usr/local/lib -lopencv_stitching -lopencv_superres ...and another libraries
Now simply add CONFIG += opencv to your .pro file to have it working. Or you can even auto-enable this feature by editing mkspecs/qconfig.pri:
/usr/share/qt5/mkspecs/qconfig.pri
...
CONFIG += ... opencv
...
BTW. qconfig.pri is a part of qt_config, which is loaded by all QMake's machine-dependent specs, so it should always work. However, it's also possible to patch only a specific spec (for example, /usr/share/qt5/mkspecs/linux-g++/qmake.conf, or whatever is appropriate for your configuration). Of course, it's even possible to add all these INCLUDEPATH+=... and LIBS+=... straight into that qmake.conf and get rid of the .prf file completely.
2) Alternatively, if you don't want to pollute Qt installation, you can use manual include:
opencv.pri
INCLUDEPATH += -I/usr/local/include/opencv
LIBS += -L/usr/local/lib -lopencv_stitching -lopencv_superres ...and another libraries
myprogram.pro
include(path/to/opencv.pri)
...
When you installed opencv you must also install the opencv.pc file, this file can be used to make it simple, since Qt supports package.config, if so, it replaces what it shows by the following:
unix: CONFIG += link_pkgconfig
unix: PKGCONFIG += opencv
Actually Qt Creator offers a simple way, you just have to right click on the name of your project and select the option Add Library:
Then you will get a dialog where you must select the type of library:
In this case I used the fourth option, and put the name of the library: opencv.
Then you press the next and finish buttons.

Path not found in .pro file in Qt

In my .pro file in Qt project, I have used these two lines for adding necessary LIBS.
LIBS += -L "../../lib/bin/libname.a"
LIBS += -L "../../rfm2g/winver/libname.lib"
error: ../../rfm2g/winver/libname.lib: No such file or directory
The compiler found the file libname.a, but could not find the libname.lib, although the relative path for both files is correct. Does anybody have an idea?
The -L option wants a directory for -l to search, not the path to the actual library.
So you should either write e.g.
LIBS += -L../../lib/bin -lname
LIBS += -L../../rfm2g/winver -lothername
Or link with them directly
LIBS += ../../lib/libname.a
LIBS += ../../rfm2g/winver/libname.lib
Also make sure that the paths actually are correct. If you change to the build directory, and try to list the files (using ls or dir depending on platform) using the paths you have, can you list both files?

Add static .a library in QtCreator

I want to use functionality of a math library ALGLIB and it's offered in .h and .cpp files. So I build it and added all the .o files to alglib.a. I copied it to my source directory and added these lines to my .pro file:
INCLUDEPATH += /path/to/ALGLIB/cpp/src
LIBS += -Lalglib
Well - I still get those "undefined reference to ..." errors when trying to build.
-L sets a directory in which the linker should search for libraries.
-l sets a library file to link in the following way: -lalglib will look for a file named libalglib.a in all directories that are set with -L
Adding a file to LIBS without anything will link that exact file.
So either:
LIBS += alglib.a
or, provided that the alglib file name is libalglib.a:
LIBS += -Lalglib-directory -lalglib