How do I enforce the order of qmake library dependencies?
Posted
by
James Oltmans
on Stack Overflow
See other posts from Stack Overflow
or by James Oltmans
Published on 2012-10-03T23:04:44Z
Indexed on
2012/10/05
3:37 UTC
Read the original article
Hit count: 218
I'm getting a lot of errors because qmake is improperly ordering the boost libraries I'm using.
Here's what .pro file looks like
QT += core gui
TARGET = MyTarget
TEMPLATE = app
CONFIG += no_keywords \
link_pkgconfig
SOURCES += file1.cpp \
file2.cpp \
file3.cpp
PKGCONFIG += my_package \
sqlite3
LIBS += -lsqlite3 \
-lboost_signals \
-lboost_date_time
HEADERS += file1.h\
file2.h\
file3.h
FORMS += mainwindow.ui
RESOURCES += Resources/resources.qrc
This produces the following command:
g++ -Wl,-O1 -o MyTarget file1.o file2.o file3.o moc_mainwindow.o -L/usr/lib/x86_64-linux-gnu -lboost_signals -lboost_date_time -L/usr/local/lib -lmylib1 -lmylib2 -lsqlite3 -lQtGui -lQtCore
Note: mylib1 and mylib2 are statically compiled by another project, placed in /usr/local/lib with an appropriate pkg-config .pc file pointing there. The .pro file references them via my_package
in PKGCONFIG
. The problem is not with pkg-config's output but with Qt's ordering.
Here's the .pc file:
prefix=/usr/local
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir=${prefix}/include
Name: my_package
Description: My component package
Version: 0.1
URL: http://example.com
Libs: -L${libdir} -lmylib1 -lmylib2
Cflags: -I${includedir}/my_package/
The linking stage fails spectacularly as mylib1 and mylib2 come up with a lot of undefined references to boost libraries that both the app and mylib1 and mylib2 are using.
We have another build method using scons and it properly orders things for the linker. It's build command order is below.
g++ -o MyTarget file1.o file2.o file3.o moc_mainwindow.o -L/usr/local/lib -lmylib1 -lmylib2 -lsqlite3 -lboost_signals -lboost_date_time -lQtGui -lQtCore
Note that the principle difference is the order of the boost libs. Scons puts them at the end just before QtGui and QtCore while qmake puts them first. The other differences in the compile commands are unimportant as I have hand modified the qmake produced make file and the simple reordering fixed the problem.
So my question is, how do I enforce the right order in my .pro file despite what qmake thinks they should be?
© Stack Overflow or respective owner