How to provide linker options when linking a static library with qmake?
In staticlib
projects, the LFLAGS
are not passed to the linker. In fact, there's no documented way to pass such flags.
The solution is generator-dependent.
For msvc_nmake
, LIBFLAGS
are passed to the linker instead. To get verbose output, you might add
QMAKE_LIBFLAGS += /VERBOSE
To verify that it works, on any system, you can invoke qmake -spec win32-msvc2008
; the particular msvc version doesn't matter.
For unixmake
, AR
is used to invoke the linker, so you have to add the flags to QMAKE_AR
. To get verbose output, you might add
QMAKE_AR += -v
To verify, invoke qmake -spec macx-llvm
; any other unix spec should work as well.
Kuba hasn't forgotten Monica
The name stays. Lest we forget. he/him All my original contributions to StackOverflow are hereby placed into the public domain. If this is not legally possible, then anyone receiving a copy of them by any means is granted a non-exclusive perpetual license to use, distribute and modify them, and to distribute modifications, under any license or none, with or without attribution. Please note that this license applies only to my original contributions - quoted material and edits by me to existing material on StackOverflow are derived works and I'm not at liberty to grant rights in them. [lifted from Steve Jessop's about me, thanks!] Most of my sscce answers are available on github: https://github.com/KubaO/stackoverflown Electronic mail: first name -at- mareimbrium -dot- org
Updated on June 18, 2022Comments
-
Kuba hasn't forgotten Monica about 2 years
I want to provide options to the linker when building a static library using qmake. Say I'd want to get verbose linker output when building with MSVC. The project file looks as follows:
# mylib.pro TEMPLATE = lib TARGET = mylib CONFIG += staticlib QT += core win32-msvc*: QMAKE_LFLAGS += /VERBOSE unix: QMAKE_LFLAGS += -v
That's the entire project file. It should result in an empty static library with no objects in it.
Setting neither
QMAKE_LFLAGS
norQMAKE_LFLAGS_STATIC_LIB
norLIBS
has any effect on the linker. Nothing set in those variables even makes it to the Makefile. IfQMAKE_LFLAGS
worked, I'd expect to see/VERBOSE
or-v
passed to the linker on the command line, as appropriate for given platform.It doesn't matter what makefile generator is used, this behavior seems to be consistent. The two platforms of interest are.
qmake -spec win32-msvc2008 qmake -spec macx-llvm
Due to cross-platform nature of qmake, you can test it on any platform where you happen to have Qt installed. This reproduces on qmake from both Qt 4.8.4 and 5.1.1. The msvc version given in the mkspec doesn't matter.