How to provide linker options when linking a static library to qmake?

I want to provide options to the linker when creating a static library using qmake. Let's say I would like to get a verbose linker when creating using MSVC. The project file is as follows:

# mylib.pro TEMPLATE = lib TARGET = mylib CONFIG += staticlib QT += core win32-msvc*: QMAKE_LFLAGS += /VERBOSE unix: QMAKE_LFLAGS += -v 

This is the entire project file. This should result in an empty static library in which there are no objects.

Setting neither QMAKE_LFLAGS , nor QMAKE_LFLAGS_STATIC_LIB , nor LIBS affects the linker. Nothing is set in these variables, even makes it in a Makefile. If QMAKE_LFLAGS worked, I expected to see /VERBOSE or -v passed to the linker on the command line, depending on the platform.

It doesn't matter which makefile generator is used, this behavior seems consistent. Two platforms of interest.

 qmake -spec win32-msvc2008 qmake -spec macx-llvm 

Due to the cross-platform nature of qmake, you can test it on any platform where you have Qt installed. This is reproduced on qmake from both Qt 4.8.4 and 5.1.1. The version of msvc specified in mkspec does not matter.

+6
source share
1 answer

In staticlib projects, staticlib LFLAGS not passed to the linker. In fact, there is no documented way to pass such flags.

The decision depends on the generator.

For msvc_nmake , LIBFLAGS instead passed to the linker. To get a detailed output, you can add

 QMAKE_LIBFLAGS += /VERBOSE 

To make sure that it works, on any system you can call qmake -spec win32-msvc2008 ; the specific version of msvc does not matter.

For unixmake , AR used to invoke the linker, so you need to add flags to QMAKE_AR . To get a detailed output, you can add

 QMAKE_AR += -v 

To check, call qmake -spec macx-llvm ; any other unix specification should work as well.

+4
source

Source: https://habr.com/ru/post/953345/


All Articles