make -j 8 g++: internal compiler error: Killed (program cc1plus)

LinuxUbuntuGccG++Mesos

Linux Problem Overview


When I deploy Apache Mesos on Ubuntu12.04, I follow the official document, in step "make -j 8" I'm getting this error in the console:

g++: internal compiler error: Killed (program cc1plus)
Please submit a full bug report,
with preprocessed source if appropriate.
See <file:///usr/share/doc/gcc-4.9/README.Bugs> for instructions.
make[2]: *** [slave/containerizer/mesos/libmesos_no_3rdparty_la-containerizer.lo] Error 1
make[2]: *** Waiting for unfinished jobs....
mv -f log/.deps/liblog_la-log.Tpo log/.deps/liblog_la-log.Plo
mv -f slave/containerizer/.deps/libmesos_no_3rdparty_la-docker.Tpo slave/containerizer/.deps/libmesos_no_3rdparty_la-docker.Plo
mv -f log/.deps/liblog_la-consensus.Tpo log/.deps/liblog_la-consensus.Plo

mv -f slave/containerizer/.deps/libmesos_no_3rdparty_la-external_containerizer.Tpo slave/containerizer/.deps/libmesos_no_3rdparty_la-external_containerizer.Plo
mv -f log/.deps/liblog_la-coordinator.Tpo log/.deps/liblog_la-coordinator.Plo
mv -f slave/.deps/libmesos_no_3rdparty_la-slave.Tpo slave/.deps/libmesos_no_3rdparty_la-slave.Plo
mv -f master/.deps/libmesos_no_3rdparty_la-master.Tpo master/.deps/libmesos_no_3rdparty_la-master.Plo
make[2]: Leaving directory `/root/Mesos/mesos/build/src'
make[1]: *** [all] Error 2
make[1]: Leaving directory `/root/Mesos/mesos/build/src'
make: *** [all-recursive] Error 1

what should I do?

Linux Solutions


Solution 1 - Linux

Try running (just after the failure) dmesg.

Do you see a line like this?

Out of memory: Kill process 23747 (cc1plus) score 15 or sacrifice child
Killed process 23747, UID 2243, (cc1plus) total-vm:214456kB, anon-rss:178936kB, file-rss:5908kB

Most likely that is your problem. Running make -j 8 runs lots of process which use more memory. The problem above occurs when your system runs out of memory. In this case rather than the whole system falling over, the operating systems runs a process to score each process on the system. The one that scores the highest gets killed by the operating system to free up memory. If the process that is killed is cc1plus, gcc (perhaps incorrectly) interprets this as the process crashing and hence assumes that it must be a compiler bug. But it isn't really, the problem is the OS killed cc1plus, rather than it crashed.

If this is the case, you are running out of memory. So run perhaps make -j 4 instead. This will mean fewer parallel jobs and will mean the compilation will take longer but hopefully will not exhaust your system memory.

Solution 2 - Linux

(Might be a memory issue)

For anybody still struggling with this (over 2 years after the question was asked), there's this trick on CryptoCurrencyTalk that seems to make it work.

For convenience I'm pasting it here:

Run these (adjust bs= and count= to the amount of swap you want)

  • sudo dd if=/dev/zero of=/swapfile bs=64M count=16
  • sudo mkswap /swapfile
  • sudo swapon /swapfile

That should let you compile your code. But make sure you then revert the swapon after compilation, with these:

  • sudo swapoff /swapfile
  • sudo rm /swapfile

Solution 3 - Linux

check if your CentOS installation already has swap enabled by typing:

sudo swapon --show

If the output is empty, it means that your system does not have swap space enabled.

Create a swap file

1.create a file which will be used as a swap space. bs is the size of one block. count is num of blocks. it will get 1024K * 1M = 1G space.

sudo dd if=/dev/zero of=/swapfile bs=1024 count=1048576

2.Ensure that only the root user can read and write the swap file:

sudo chmod 600 /swapfile

3.set up a Linux swap area on the file

sudo mkswap /swapfile

4.activate the swap

sudo swapon /swapfile

5."sudo swapon --show" or "sudo free -h" you will see the swap space.

Solution 4 - Linux

This was the clue in my scenario (compiling mesos on CentOS 7) on an AWS EC2 instance.

I fixed it by increasing memory and cpu to at least 4GiB and 2 vCPUs.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionpugnaView Question on Stackoverflow
Solution 1 - LinuxJon CombeView Answer on Stackoverflow
Solution 2 - LinuxribbitView Answer on Stackoverflow
Solution 3 - LinuxLi YingjunView Answer on Stackoverflow
Solution 4 - LinuxTraiano WelcomeView Answer on Stackoverflow