QMake Linking Problem With GCC - c++

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

Related

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

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

Including headers from /usr/local/include and libraries from /usr/local/lib

I have just installed GLFW on OS X 10.9. The headers were installed to /usr/local/include and the library was installed in /usr/local/lib.
I am wondering what else I would have to do to get my C++ program to include the headers like #include "GLFW/glfw3.h" rather than specifying the whole path like #include "usr/local/include/GLFW/glfw3.h".
Same thing goes for the library because as of now I can't even link the library using -lglfw3. Thanks in advance.
You would pass -I /usr/local/include to the compiler as preprocessor flag, and -L /usr/local/lib to the compiler as linker flag. So to build a single source application small.cc compile it as
g++ -Wall -I /usr/local/include -L /usr/local/lib \
small.cc -o small -lglfw3
If building with make just have
CXXFLAGS += -I/usr/local/include
LDFLAGS += -L/usr/local/lib
in your Makefile
If using shared libraries, add once /usr/local/lib to /etc/ld.so.conf and run ldconfig (at least on Linux).

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.