Skip to content
Latchkey

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++ output
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 4

Common 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.

Terminal
cmake --build build -- -j2
# or with make/ninja directly
make -j2
ninja -j2 -C build

Give 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.

  1. Move the job to a higher-RAM runner class.
  2. Split or refactor the heaviest translation units.
  3. Reduce optimization level (-O1) on the heaviest files if needed.

How to prevent it

  • Cap -j to 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.

Frequently asked questions

Is "internal compiler error: Killed" a bug in GCC?
No. "Killed" means an external signal (SIGKILL from the OOM killer) terminated the process. A genuine GCC ICE prints a different message and a backtrace. This one is purely about memory.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →