I have been learning CMake and am having persistent build issues with the library Catch2.
I am using Qt as my IDE and have downlaoded Qt6 and MinGW 8 via the Qt maintainance tool.
My issue seems to be that during compilation my test/main.cpp, which includes Catch2, is bloating to the point where the compiler errors.
14:57:22: Running steps for project CMakeTestbed...
14:57:22: Starting: "<dir>\CMake\bin\cmake.exe" --build . --target all
[0/1 ?/sec] Re-running CMake...
-- Could NOT find Vulkan (missing: Vulkan_INCLUDE_DIR)
-- Using the single-header code from <dir>/build-CMakeTestbed-Desktop_Qt_6_0_0_MinGW_64_bit-Debug/_deps/json-src/single_include/
-- Version: 7.1.3
-- Build type: Debug
-- CXX_STANDARD: 17
-- Required features: cxx_variadic_templates
-- Configuring done
-- Generating done
-- Build files have been written to: <dir>/build-CMakeTestbed-Desktop_Qt_6_0_0_MinGW_64_bit-Debug
[1/17 3.7/sec] Automatic MOC and UIC for target fmt
[2/15 5.6/sec] Automatic MOC and UIC for target Catch2WithMain
[3/14 6.8/sec] Automatic MOC and UIC for target CMakeTestbedLib
[4/12 3.6/sec] Automatic MOC and UIC for target CMakeTestbed
[5/10 4.5/sec] Automatic MOC and UIC for target Tests
[6/9 0.4/sec] Building CXX object _deps/catch2-build/CMakeFiles/Catch2WithMain.dir/src/catch_with_main.cpp.obj
FAILED: _deps/catch2-build/CMakeFiles/Catch2WithMain.dir/src/catch_with_main.cpp.obj
C:\Qt\Tools\mingw810_64\bin\g++.exe -I_deps/catch2-build -I_deps/catch2-src -I_deps/catch2-build/Catch2WithMain_autogen/include -I_deps/json-src/include -I_deps/fmt-src/include -I_deps/catch2-src/single_include -g -std=gnu++17 -MD -MT _deps/catch2-build/CMakeFiles/Catch2WithMain.dir/src/catch_with_main.cpp.obj -MF _deps\catch2-build\CMakeFiles\Catch2WithMain.dir\src\catch_with_main.cpp.obj.d -o _deps/catch2-build/CMakeFiles/Catch2WithMain.dir/src/catch_with_main.cpp.obj -c _deps/catch2-src/src/catch_with_main.cpp
C:/Qt/Tools/mingw810_64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/as.exe: _deps/catch2-build/CMakeFiles/Catch2WithMain.dir/src/catch_with_main.cpp.obj: too many sections (32805)
<dir>\AppData\Local\Temp\ccE30B5r.s: Assembler messages:
<dir>\AppData\Local\Temp\ccE30B5r.s: Fatal error: can't write 233 bytes to section .text of _deps/catch2-build/CMakeFiles/Catch2WithMain.dir/src/catch_with_main.cpp.obj: 'File too big'
C:/Qt/Tools/mingw810_64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/as.exe: _deps/catch2-build/CMakeFiles/Catch2WithMain.dir/src/catch_with_main.cpp.obj: too many sections (32805)
<dir>\AppData\Local\Temp\ccE30B5r.s: Fatal error: can't close _deps/catch2-build/CMakeFiles/Catch2WithMain.dir/src/catch_with_main.cpp.obj: File too big
[7/9 0.4/sec] Building CXX object test/CMakeFiles/Tests.dir/main.cpp.obj
FAILED: test/CMakeFiles/Tests.dir/main.cpp.obj
C:\Qt\Tools\mingw810_64\bin\g++.exe -DFMT_LOCALE -DJSON_USE_IMPLICIT_CONVERSIONS=1 -Itest -I"<dir>/CMakeTestbed/test" -Itest/Tests_autogen/include -I_deps/json-src/include -I_deps/fmt-src/include -I_deps/catch2-src/single_include -I"<dir>/CMakeTestbed/test/../libs" -I"<dir>/CMakeTestbed/test/../src" -I_deps/json-src/single_include -g -std=gnu++17 -MD -MT test/CMakeFiles/Tests.dir/main.cpp.obj -MF test\CMakeFiles\Tests.dir\main.cpp.obj.d -o test/CMakeFiles/Tests.dir/main.cpp.obj -c "<dir>/CMakeTestbed/test/main.cpp"
C:/Qt/Tools/mingw810_64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/as.exe: test/CMakeFiles/Tests.dir/main.cpp.obj: too many sections (32805)
<dir>\AppData\Local\Temp\ccARyb79.s: Assembler messages:
<dir>\AppData\Local\Temp\ccARyb79.s: Fatal error: can't write 233 bytes to section .text of test/CMakeFiles/Tests.dir/main.cpp.obj: 'File too big'
C:/Qt/Tools/mingw810_64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/as.exe: test/CMakeFiles/Tests.dir/main.cpp.obj: too many sections (32805)
<dir>\AppData\Local\Temp\ccARyb79.s: Fatal error: can't close test/CMakeFiles/Tests.dir/main.cpp.obj: File too big
ninja: build stopped: subcommand failed.
14:57:49: The process "C:\Program Files\CMake\bin\cmake.exe" exited with code 1.
Error while building/deploying project CMakeTestbed (kit: Desktop Qt 6.0.0 MinGW 64-bit)
When executing step "Build"
These issues only occur in debug builds, so I believe the combination of heavy templating, along with the debug symbols is hitting some MinGW compiler threshold...
I am trying something like
target_compile_options(Tests
-Wa
-mbig-obj
)
(Doesn't seem to actually be valid CMake, tried without the '-' too, regardless, this doesn't fix the problem, just hides it...)
But it seems to me the best option would be to make the library precompile in release (I don't need to debug the Catch2 internals, if I am debugging, it is because I have a broken test that I am investigating, and I shouldn't need the dirty details of the lib internals to do that right?)
I have a minimal working example here https://github.com/SebastianTroy/CMakeTestbed.
The main files of interest here would be:
- catch2.cmake (from https://github.com/catchorg/Catch2/blob/v2.x/docs/cmake-integration.md#cmake-target)
- test/CMakeLists.txt (includes Catch2)
- test/main.cpp (the unit that is failing to compile)
I would really appreciate some help with either forcing CMake to precompile the library with higher optimisation flags than the target (to prevent the issue altogether) I would settle for help telling the compiler to ignore the overly large file (to just sidestep the issue)