Linux上的这个GCC错误是什么,我该如何解决? gcc:内部编译器错误:非法指令(程序为)
我输入gcc hello.c
,这会出现:
gcc: internal compiler error: Illegal instruction (program as) Please submit a full bug report, with preprocessed source if appropriate. See for instructions.
hello.c只是:
int main() { return 0; }
我想不出有什么方法可以让它更简单! (那里的printf
也是如此。)
那么:你如何解决这个问题? 我在Raspberry Pi上的Raspian上。
编辑
gcc -v给出
Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/lib/gcc/arm-linux-gnueabihf/4.6/lto-wrapper Target: arm-linux-gnueabihf Configured with: ../src/configure -v --with-pkgversion='Debian 4.6.3-14+rpi1' --with-bugurl=file:///usr/share/doc/gcc-4.6/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.6 --enable-shared --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.6 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --enable-plugin --enable-objc-gc --disable-sjlj-exceptions --with-arch=armv6 --with-fpu=vfp --with-float=hard --enable-checking=release --build=arm-linux-gnueabihf --host=arm-linux-gnueabihf --target=arm-linux-gnueabihf Thread model: posix gcc version 4.6.3 (Debian 4.6.3-14+rpi1)
不,我没有安装它。
至于更新, sudo apt-get install gcc
给出
Reading package lists... Done Building dependency tree Reading state information... Done gcc is already the newest version. 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
是的,你可以运行,它说没有参数的Illegal instruction
。
我不知道交换空间是什么。
gcc -O0 -g hello.c
给出了同样的错误。
gcc无法识别--enable-debug
。
得到它了! 我卸载了gcc,安装了gcc-4.7,并且……没有。
我清除了gcc-4.6的结束并重新运行sudo apt-get install gcc-4.7
并且……没有。
我更新了binutils并且…它工作了!
因此,似乎没有更新GCC的影响,但更直接地更新它对我来说。
(这是从2.22-7.1到2.22-8,如果这有助于任何人。)
我只能对错误信息有所了解:
gcc:内部编译器错误:非法指令(程序为)
gcc在编译时做了几件事。 它首先将您的C程序转换为汇编程序,然后将汇编程序转换为机器代码。
使用gcc的汇编程序的名称也是as
。 因此错误消息告诉您,运行汇编程序失败,因为汇编程序可执行文件包含非法指令。
这可能真的是硬件错误,这意味着汇编程序的可执行文件已被破坏。
去检查:
-
gcc -S hello.c
吗? 这应该创建一个“hello.s”,其中包含编译为汇编程序的C代码 - 您可以尝试使用
gcc -v -c hello.c
来找出确切的结果。
在raspberryPi论坛上找到:
抓取源代码并尝试在x86-64盒子上进行交叉编译以获得通用臂目标。 filter / hq2x.cpp中的内容导致GCC疯狂并消耗内存和交换,所以如果它在Pi上触发致命错误,我不会感到惊讶。 一些消息来源表明编译器(cc1plus)内部堆栈溢出。
一个可能的解决方法是使用–enable-debug运行configure脚本 – 这应该将优化降至最低,并以增加二进制大小为代价避免堆栈溢出。
所以你可以尝试设置编译器标志
-O0 -g
并检查是否有帮助。
有类似的问题。
但它发生在VirtualBox图像(使用Xubuntu 16.04 / gcc-5)从基于Haswell的机器移动到Sandy Bridge之后。 问题出现在build-essential / gcc / binutils包中。 我重新安装了所有这些(使用apt删除和apt安装 – 没有oneshot重新安装) – 它帮助。
尝试更新编译器并尝试
sudo apt-get install build-essential
这可能会解决问题。