Automoc + static plugins = build error
I have a project¹ that, as part of an executable target, builds several Qt plugins which are then statically linked and loaded. This is currently working with qtN_wrap_cpp
, however when trying to replace that with automoc, I am getting a bunch of errors:
In file included from Applications/VsPlay/vsPlay_autogen/mocs_compilation.cpp:7:
Applications/VsPlay/vsPlay_autogen/SW3NWFZ6YS/moc_vsVvqsDatabaseSourcePlugin.cpp: At global scope:
Applications/VsPlay/vsPlay_autogen/SW3NWFZ6YS/moc_vsVvqsDatabaseSourcePlugin.cpp:95:39: error: redefinition of ‘const uint qt_section_alignment_dummy’
QT_PLUGIN_METADATA_SECTION const uint qt_section_alignment_dummy = 42;
^~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from Applications/VsPlay/vsPlay_autogen/mocs_compilation.cpp:2:
Applications/VsPlay/vsPlay_autogen/SW3NWFZ6YS/moc_vsDescriptorArchiveSourcePlugin.cpp:95:39: note: ‘const uint qt_section_alignment_dummy’ previously defined here
QT_PLUGIN_METADATA_SECTION const uint qt_section_alignment_dummy = 42;
^~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from Applications/VsPlay/vsPlay_autogen/mocs_compilation.cpp:7:
Applications/VsPlay/vsPlay_autogen/SW3NWFZ6YS/moc_vsVvqsDatabaseSourcePlugin.cpp:100:46: error: redefinition of ‘const unsigned char qt_pluginMetaData []’
static const unsigned char qt_pluginMetaData[] = {
^
In file included from Applications/VsPlay/vsPlay_autogen/mocs_compilation.cpp:2:
Applications/VsPlay/vsPlay_autogen/SW3NWFZ6YS/moc_vsDescriptorArchiveSourcePlugin.cpp:100:28: note: ‘const unsigned char qt_pluginMetaData [280]’ previously defined here
static const unsigned char qt_pluginMetaData[] = {
^~~~~~~~~~~~~~~~~
(Note: this project is also in the process of transitioning to Qt5. As the problematic code relates to the new Qt5 way of registering plugins, it is possible this wouldn't be a problem with Qt4. However I have not tested that combination.)
Each plugin moc source has a declaration like static const unsigned char qt_pluginMetaData[] = { ... };
. When using qtN_wrap_cpp
, this is fine, because each plugin is a separate TU. However, it appears that automoc, rather than compiling each moc source separately, is #include
ing them all in one monolithic mocs_compilation.cpp
?
This... seems dodgy. In particular, it can't possibly work for my use case.