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?
Related
I want to use tensorflow_cc library in QT creater
I tried linking the libtensorflow_cc.so in .pro file but I'm still unable to access the header files.
test.pro file:
LIBS += -L/usr/local/lib/ -ltensorflow_cc
INCLUDEPATH += /usr/local/lib/
test.cpp file:
#include <tensorflow/core/platform/env.h>
error :
tensorflow/core/platform/env.h: No such file or Directory
I have added the path of the .so file to LD_LIBRARY_PATH. Is there anyway to include the tensorflow library and use the header files in QT.
This is a similar question but it didn't quite help me.
Thanks!
Add this to the .pro file:
LIBS += /usr/lib/libtensorflow_cc.so
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.
I am trying to run OpenALPR on QT. I installed it here. I can test it from terminal successfully. I got the error in the title on QT. Undefined reference error is caused by unlinked library but I add the libopenalpr.so under the path /usr/lib to the .pro file. Why I get that error?
My cpp file:
#include "alpr.h"
int main()
{
alpr::Alpr openalpr("us", "etc/openalpr/openalpr.conf");
}
My pro file:
QT += core
QT -= gui
TARGET = OpenAlprTry
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
LIBS += -L -lopenalpr
You can use pkg-config to link with your wanted library.
Add to .pro file:
unix: CONFIG += link_pkgconfig
unix: PKGCONFIG += openalpr
Package name could be different or you could need to add more packages.
To check pkg-config names type in your terminal:
pkg-config --list-all | grep openalpr
and add packages like that
unix: PKGCONFIG += package1 package2 package3
Can you first check whether openalpr library is in the library path? IF not add the library path to the .pro file.
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
I'm using Qt Creator 2.7.0 on ubuntu 13.04.
I've just recently ran into the idea of using libraries, and they're a whole new thing for me.
I've just figured that I need to have the following in my application's .pro file to use a library of my own:
LIBS += -L<lib's dir> -l<lib's name>
INCLUDEPATH += <headers' dir>
// for example:
LIBS += -L$$PWD/../MyLib/release/ -lMyLib
INCLUDEPATH += $$PWD/../MyLib/src/
As you see, I have all my projects in a folder called Programming (the .. in this case)
Each of my project have .pro and .pro.user files in the root, source files in a sub folder /src and the release in an other sub folder /release.
So, this is what my Programming folder looks like:
Programming
MyLib
MyLib.pro
MyLib.pro.user
src
myclass.h
myclass.cpp
release
libMyLib.a
Makefile
myclass.o
MyApp
MyApp.pro
MyApp.pro.user
src
main.cpp
release
main.o
Makefile
MyApp
However, I figured that I could create a folder Programming/libs/, and add libMyLib.a and myclass.h files inside that libs folder.
I would do the same for all of my libraries, and then I could always include them like this:
LIBS += -L$$PWD/../lib/ -lMyLib
INCLUDEPATH += $$PWD/../lib/
The problem is, I'd get include path for every library stored on my computer and the libs folder would become a mess, especially if there are two headers with same name on different libraries.
I'm really new to using libraries, is there a general solution on how they should be located on your computer, and how to include them into your projects?
You could mimic libraries like Boost and have a directory tree like this:
MyLib
build
Makefile, .pro or .sln file here
lib
MyLib
// your .so / .a here
include
MyLib
// your .h here
src
// your .cpp here
CMake or qmake file here
This way you have an out-of-source build tree (in build/) so that your binary files are not mixed up with your source files.
The lib/ and include/ directories are handy because you can then define an install build target. If you then type
make install
it will copy everything to usr/local/lib and user/local/include so that your App can simply do #include <MyLib/some_header.h> and you can link directly against your library binaries (because you copied everything to a location in your system wide path). There is also no danger of name clashes because you wrapped it inside your own MyLib subdirectory.