无人机仿真配置PX4飞控make编译’make px4_sitl_default gazebo’报错internal compiler error: killed (program cc1plus)解决办法

发布于 2021-01-04  1096 次阅读


一、背景

在采用Gazebo进行无人机平台下仿真实验时,编译PXhawk飞控代码报错:

[11/33] Building CXX object CMakeFiles...plugin.dir/src/gazebo_uuv_plugin.cpp.o
FAILED: /usr/bin/c++   -DQT_CORE_LIB -DQT_GUI_LIB -DQT_NO_DEBUG -Dgazebo_uuv_plugin_EXPORTS -isystem /usr/include/qt4 -isystem /usr/include/qt4/QtGui -isystem /usr/include/qt4/QtCore -isystem /usr/include/gazebo-7 -isystem /usr/include/sdformat-4.4 -isystem /usr/include/ignition/math2 -isystem /usr/include/OGRE -I/home/weiweu/PX4_Firmware/Tools/sitl_gazebo/include -I. -I/usr/include/eigen3 -I/usr/include/eigen3/eigen3 -I/usr/include/gazebo-7/gazebo/msgs -I/home/weiweu/PX4_Firmware/mavlink/include -I/usr/include/OGRE/Paging -isystem /opt/ros/kinetic/include/opencv-3.3.1-dev -isystem /opt/ros/kinetic/include/opencv-3.3.1-dev/opencv -I/home/weiweu/PX4_Firmware/Tools/sitl_gazebo/external/OpticalFlow/include -I/usr/include/gstreamer-1.0 -I/usr/lib/x86_64-linux-gnu/gstreamer-1.0/include -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -Wno-deprecated-declarations -Wno-address-of-packed-member -fPIC   -std=gnu++14 -MMD -MT CMakeFiles/gazebo_uuv_plugin.dir/src/gazebo_uuv_plugin.cpp.o -MF CMakeFiles/gazebo_uuv_plugin.dir/src/gazebo_image_plugin.cpp.o.d -o CMakeFiles/gazebo_uuv_plugin.dir/src/gazebo_uuv_plugin.cpp.o -c /home/weiweu/PX4_Firmware/Tools/sitl_gazebo/src/gazebo_uuv_plugin.cpp
c++: internal compiler error: 已杀死 (program cc1plus)
Please submit a full bug report,
with preprocessed source if appropriate.
See <file:///usr/share/doc/gcc-5/README.Bugs> for instructions.
[11/33] Building CXX object CMakeFiles...dir/src/gazebo_mavlink_interface.cpp.o
ninja: build stopped: subcommand failed.
[2/5] Generating ../../logs
FAILED: cd /home/weiweu/PX4_Firmware/build/px4_sitl_default/build_gazebo && /usr/bin/cmake --build .
ninja: build stopped: subcommand failed.
Makefile:198: recipe for target 'px4_sitl_default' failed
make: *** [px4_sitl_default] Error 1

分析

本次报错无源代码原因,没有因为.cpp文件的类型等错误信息或是缺失各种依赖库,而是进程被强制终止了:internal compiler error: killed (program cc1plus)

分析error.README.log推断为内存不够,由于在Ubuntu平台下,可在编译的此次运行中提高虚拟内存的大小。

二、解决方案

# of=/home/swap:放置swap的空间
#分配1024MB(1G)的块大小,所以总共空间就是bs*count=4GB.分配空间需要一点时间,需要稍稍等待
sudo dd if=/dev/zero of=/home/swap bs=102M count=4

#把刚才空间格式化成swap格式
sudo mkswap /home/swap

#使刚才创建的swap空间
sudo swapon /home/swap

随后再次执行make px4_sitl_default gazebo,此步骤耗时较久,需要耐心等待,不然就要重复我的失败:一久就卡顿,卡顿就强制重来,结果编译了两天!

好在,后来佛系编译,一晚上自己跑完了(一大堆l是编译的时候出现的.....弹出个界面被我掐掉了,可以自己尝试):
file