Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Servers, nginx and Docker

g++ stops with 'Killed (program cc1plus)' during make -j

Errorg++: internal compiler error: Killed (program cc1plus)

Short answer

Killed means the kernel ended the compiler because the machine ran out of memory, so it is not a bug in your code. Many parallel cc1plus processes each use a lot of RAM. Build with fewer jobs, add swap space, or compile the heavy files with less optimisation.

  • Applies to GCC 13, GNU make 4.3, Ubuntu 24.04
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Check the kernel log for an out-of-memory kill at the time the build died, and see how much memory and swap the machine has.

    sudo dmesg | grep -i -E 'out of memory|killed process'
    free -h
  2. 2Match what you see, then jump to its fix

    1. 1the build only fails with -j N and passes with a lower numberToo many parallel compile jobs for the RAMFix
    2. 2free -h shows Swap: 0BThere is no swap to absorb a spikeFix
    3. 3only the same file is killed, even with -j1One huge source file needs more memory than the restFix

What does the error look like?

  • g++: internal compiler error: Killed (program cc1plus)
  • Killed (program cc1plus)

Cause 1 of 3

Too many parallel compile jobs for the RAM

1Check

make -j N runs N recipes at once, and each one starts its own cc1plus. With no number, make sets no limit. The kernel's OOM killer picks a large memory user to sacrifice when memory runs out.

nproc
free -h

2Fix

Run fewer jobs, or let make stop starting new jobs while the load average is high with -l.

make -j2
make -j8 -l 4

3Verify

Repeat the build and watch the kernel log stay quiet.

make -j2
sudo dmesg | grep -i 'killed process' || echo none

Confirmed by gnu.org

Did this fix it?

Cause 2 of 3

There is no swap to absorb a spike

1Check

The kernel calls the OOM killer only when reclaiming pages fails, and having swap left is one of the checks that can rule it out. A small VM with no swap hits it quickly.

swapon --show

2Fix

Create a swap file with mkswap --file, then enable it with swapon. Check swapon(8) for the restrictions on swap files.

sudo mkswap --size 4G --file /swapfile
sudo swapon /swapfile

3Verify

Swap now shows in the listing.

swapon --show

Confirmed by man7.org

Did this fix it?

Cause 3 of 3

One huge source file needs more memory than the rest

1Check

Optimising compilation takes a lot more memory for a large function, and -fipa-pta can use excessive memory on large compilation units. Check the flags in the build.

grep -rn -E -- '-O[0-9s]|-fipa-pta' Makefile* CMakeLists.txt 2>/dev/null | head

2Fix

Build that file with a lower optimisation level, and remove -fipa-pta if the build sets it.

make CXXFLAGS='-O1'

3Verify

The file compiles to the end.

make -j1

Confirmed by gcc.gnu.org

Did this fix it?

How do I stop it coming back?

  • Pick -j from the memory you have, not only from the core count.
  • Keep a swap file on small build machines.
  • Read dmesg after a Killed message before you change any code.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Related fixes

Servers

dnf cannot install MySQL on Amazon Linux 2023

dnf cannot find a mysql-server package on Amazon Linux 2023

Amazon Linux 2023 documents MariaDB, not MySQL, as its database server, with packages named mariadb105 and mariadb105-server.

3 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.