AUTOMOC: mocs_compilation.cpp can grow too big for MinGW
When compiling a Qt project with AUTOMOC
, all generated moc
output files are compiled as a single translation unit, mocs_compilation.cpp
, which includes all files generated by moc
.
When compiling large projects with MinGW, this translation unit can grow too big for the resulting .obj
file, even with the -Wa,-mbig-obj
flag set (see https://digitalkarabela.com/mingw-w64-how-to-fix-file-too-big-too-many-sections/):
FAILED: …_autogen/mocs_compilation.cpp.obj
ccache /usr/bin/x86_64-w64-mingw32-g++ -DBOOST_NO_AUTO_PTR -DQT_CHARTS_LIB -DQT_CORE_LIB -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_OPENGL_LIB -DQT_PRINTSUPPORT_LIB -DQT_WIDGETS_LIB -DQWT_DLL … -Wall -g -Wa,-mbig-obj -Wa,-mbig-obj -std=gnu++2a -MD -MT …_autogen/mocs_compilation.cpp.obj -MF …_autogen/mocs_compilation.cpp.obj.d -o …_autogen/mocs_compilation.cpp.obj -c …_autogen/mocs_compilation.cpp
/usr/bin/x86_64-w64-mingw32-as: libs/src/frontend/CMakeFiles/FrontendLibs.dir/FrontendLibs_autogen/mocs_compilation.cpp.obj: section .debug_frame$_ZSt7forwardIRKSt10shared_ptrIN3…: string table overflow at offset 10000081
/tmp/ccqeFGg4.s: Assembler messages:
/tmp/ccqeFGg4.s: Fatal error: can't close …_autogen/mocs_compilation.cpp.obj: file too big
(note: Some parts of the output have been removed.)
In this case, there are approximately 250 moc
output files included in this translation unit.
To resolve this, I suggest the moc
output files are compiled as individual translation units instead of bundling them up into a singe big one.