g++ "internal compiler error: Killed (program cc1plus)" - OOM
This "internal compiler error" is not a compiler bug - the OS out-of-memory killer terminated cc1plus (the C++ compiler) mid-compile. The runner ran out of RAM, usually from too many parallel compiles.
What this error means
A compile dies with "internal compiler error: Killed (program cc1plus)". It is intermittent - it strikes the heaviest translation unit or a high -j level - and a dmesg shows an OOM kill.
g++: internal compiler error: Killed (program cc1plus)
Please submit a full bug report, with preprocessed source if appropriate.
make: *** [CMakeFiles/app.dir/big_tu.cpp.o] Error 4Common causes
Too many parallel compiles for the RAM
Each cc1plus can use hundreds of MB to gigabytes on heavy templated code. A high -j (e.g. -j$(nproc)) multiplies that past the runner’s memory and the OOM killer steps in.
One very heavy translation unit
Deep template instantiation or huge generated/aggregated files can exhaust memory on a single compile even at low parallelism.
How to fix it
Reduce build parallelism
Lower the job count so concurrent compilers fit in RAM. This is the quickest fix for an OOM-killed compile.
cmake --build build -- -j2
# or with make/ninja directly
make -j2
ninja -j2 -C buildGive the build more memory
Run on a larger runner, or cap memory pressure per job. Latchkey can retry an OOM-killed build on a higher-memory runner automatically.
- Move the job to a higher-RAM runner class.
- Split or refactor the heaviest translation units.
- Reduce optimization level (
-O1) on the heaviest files if needed.
How to prevent it
- Cap
-jto a value that fits the runner’s memory, not just its CPU count. - Run heavy C++ builds on memory-sized runners.
- Split monolithic translation units that dominate memory use.