Meaning of LIBS += -L/user/lib/something (in QMake script) - c++

I had the problem that my Library libboost_system was not working, then I added this line in my linker, and after that it works:
LIBS += -L/usr/lib/x86_64-linux-gnu -lboost_system
So my qustion is; what does -L mean here?
and why the project won't compile without it?
thanks

Related

gcc linker can't find library

I get a strange error while building my Qt C++ project on Ubuntu Linux using GCC 5.2.1:
/usr/bin/ld: cannot find -llibmath
I include external dynamic library to maky qmake project using command:
LIBS += -L/home/rem -llibmath
and I have library file at path /home/rem/libmath.so
As I can see from compiler output:
g++ -Wl,-rpath,/home/rem/Qt/5.5/gcc_64 -Wl,-rpath,/home/rem/Qt/5.5/gcc_64/lib -o Bazis main.o builder.o -L/home/rem -llibmath -L/home/rem/Qt/5.5/gcc_64/lib -lQt5OpenGL -L/usr/lib64 -lQt5QuickWidgets -lQt5Widgets -lQt5Quick -lQt5Gui -lQt5Sql -lQt5Test -lQt5Qml -lQt5Network -lQt5Core -lGL -lpthread
all parameters are correctly send by qmake to g++.
What is the source of my problem?
The solution is simple:
I changed my .pro file from:
LIBS += -L/home/rem -llibmath
to:
LIBS += -L/home/rem -lmath

How to supply compiler options in Qt?

I am trying to learn Qt, I have file test.cpp that I run via the terminal using the following command:
g++ `pkg-config --cflags --libs libsbml` test.cpp -L /usr/local/lib -lsbml -lstdc++ -lm
How can I suppl the same options to Qt?
Thank you.
You could write the qmake snippet below. In short, you would need to take a look at the following qmake variables:
LIBS
INCLUDEPATH
TEMPLATE
TARGET
HEADERS
SOURCES
CONFIG
PKGCONFIG
test.pro
TEMPLATE = app
TARGET = test
INCLUDEPATH += .
LIBS += -L /usr/local/lib -lsbml -lstdc++ -lm
unix {
CONFIG += link_pkgconfig
PKGCONFIG += libsbml
}
HEADERS += test.h
SOURCES += test.cpp
In .pro file add:
LIBS += -L /usr/local/lib -lsbml -lstdc++ -lm
look at the Makefile to figure out what variables are used. The makefile is in the build folder made by Qt.

qmake doesn't add libraries from .pro file to the makefile

I try to build an QT project using qmake. For this I need the boost library.
LIBS += -L/usr/lib/ \
-lboost_system \
-lboost_filesystem
But after running qmake, these libraries are not added to the makefile:
LIBS = $(SUBLIBS) -L/usr/X11R6/lib64 -lQt5MultimediaWidgets
-L/build/buildd/qtmultimedia-opensource-src-5.0.1/lib -L/usr/lib/x86_64-linux-gnu
-L/usr/lib/x86_64-linux-gnu/x86_64-linux-gnu -lQt5OpenGL -lQt5Multimedia -lpulse
-lQt5Widgets -lQt5Network -lQt5Gui -lQt5Core -lGL -lpthread
As expected, the linker prints many error like
/usr/include/boost/system/error_code.hpp:214: error: undefined reference to boost::system::generic_category()
If you want to take a look to the whole .pro file, go to https://raw.github.com/francisengelmann/FabScan100/master/qtTest/qtTest.pro
I am also having a similar problem with opencv. Does anyone know how to solve this issue ?
You need to run qmake again after changing the .pro file. Just removing your build directory is not enough.
Also are you sure your qmake target is linux-g++? Does the INCLUDEPATH work?

qt project file Library includes

I know that the library required can be loaded with
LIBS += -L/path/to/lib
recently I have found something like this
LIBS += -L. -L/usr/lib -lphonon -lcurl -ltag -fopenmp -lsayonara_gstreamer
What does "-L." means ?
Uppercase -L increments the libraries search path, while lowercase -l add a library. Then -L. add the build directory as possible recipe of some of the listed libraries.

QMake Linking Problem With GCC

I have a problem with qmake and the make file that it generates. My program needs to be linked against two libraries. I add them in main.pro as follows.
LIBS += -L lib/somelib1/bin -lsomelib1 -L lib/somelib2/bin -lsomelib2
How ever I arrange the above line qmake tells gcc this.
g++ -o programname someobject.o -L lib/somelib1/bin lib/somelib2/bin -lsomelib1 -lsomelib2
The problem is that it should look like this.
g++ -o programname someobject.o -L lib/somelib1/bin -L lib/somelib2/bin -lsomelib1
-lsomelib2
GCC gives the following error.
lib/somelib2/bin: file not recognized: Is a directory
Thanks in advance.
You should not put spaces between the flags and the arguments:
LIBS += -Llib/somelib1/bin -lsomelib1 -Llib/somelib2/bin -lsomelib2
Or
LIBS += -L"lib/somelib1/bin" -lsomelib1 -L"lib/somelib2/bin" -lsomelib2
And why are your static/import libraries in the "bin" directory? There should be .a files in the "lib" directory.
You could try putting the library search paths under the QMAKE_LIBDIR tag. So your qmake file would have:
QMAKE_LIBDIR += lib/somelib1/bin lib/somelib2/bin
LIBS += -lsomelib1 -lsomelib2