[cmake-developers] Linking to OBJECT libraries?
Stephen Kelly
steveire at gmail.com
Thu Jun 6 08:09:35 EDT 2013
Hi,
I've been working on a patch to make it easier to use CMake with a
statically built Qt 5:
https://codereview.qt-project.org/#change,56215
A complexity arises in that all Qt 5 applications must load a platform
plugin. If Qt is built statically, the platform plugin must be loaded by
using the Q_IMPORT_PLUGIN macro.
Rather than forcing all Qt-using code to have a shared/static specific
snippet, qmake generates a small file like this:
#include <QtPlugin>
Q_IMPORT_PLUGIN(QXcbIntegrationPlugin) // Or Win plugin on Windows.
and compiles it into the executable.
In my patch above I tried a similar approach by creating a static library
with the above snippet and adding it to the link interface of Qt5::Gui.
However, the plugin import code does not get executed at runtime. I assume
the linker ignores the code because the executable doesn't use any symbols
from it.
The solution would be to generate an OBJECT library instead of a static
library. However, it is not possible to link to an OBJECT library currently.
I was wondering why that is, and if it can be changed? Alternatively, can
you think of any other solutions for this? I don't want to require people to
have to use something like:
add_executable(myexe ${Qt5StaticObjectPluginLoader} main.cpp)
Thanks,
Steve.
More information about the cmake-developers
mailing list