G ++认为浮动是非法指令

时间:2016-12-29 17:45:47

标签: c++ gcc floating-point g++ gnu

在我的文件“six.cpp”中,我尝试打印一个浮点数,但编译器不断抛出错误。这是文件“six.cpp”:

#include <iostream>
#include <iomanip>
using namespace std;

int main(){
  double f = 5.3;
  cout << f << endl;
  return 0;
}

然后当我尝试使用g++ six.cpp进行编译时,我使用-v标记获得以下输出。

Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-cygwin/4.9.3/lto-wrapper.exe
Target: x86_64-pc-cygwin
Configured with: /cygdrive/i/szsz/tmpp/gcc/gcc-4.9.3-1.x86_64/src/gcc-4.9.3/configure --srcdir=/cygdrive/i/szsz/tmpp/gcc/gcc-4.9.3-1.x86_64/src/gcc-4.9.3 --prefix=/usr --exec-prefix=/usr --localstatedir=/var --sysconfdir=/etc --docdir=/usr/share/doc/gcc --htmldir=/usr/share/doc/gcc/html -C --build=x86_64-pc-cygwin --host=x86_64-pc-cygwin --target=x86_64-pc-cygwin --without-libiconv-prefix --without-libintl-prefix --libexecdir=/usr/lib --enable-shared --enable-shared-libgcc --enable-static --enable-version-specific-runtime-libs --enable-bootstrap --enable-__cxa_atexit --with-dwarf2 --with-tune=generic --enable-languages=ada,c,c++,fortran,lto,objc,obj-c++ --enable-graphite --enable-threads=posix --enable-libatomic --enable-libgomp --disable-libitm --enable-libquadmath --enable-libquadmath-support --enable-libssp --enable-libada --enable-libgcj-sublibs --disable-java-awt --disable-symvers --with-ecj-jar=/usr/share/java/ecj.jar --with-gnu-ld --with-gnu-as --with-cloog-include=/usr/include/cloog-isl --without-libiconv-prefix --without-libintl-prefix --with-system-zlib --enable-linker-build-id
Thread model: posix
gcc version 4.9.3 (GCC)
COLLECT_GCC_OPTIONS='-v' '-mtune=generic' '-march=x86-64'
 /usr/lib/gcc/x86_64-pc-cygwin/4.9.3/cc1plus.exe -quiet -v -Dunix -idirafter /usr/lib/gcc/x86_64-pc-cygwin/4.9.3/../../../../lib/../include/w32api -idirafter /usr/lib/gcc/x86_64-pc-cygwin/4.9.3/../../../../x86_64-pc-cygwin/lib/../lib/../../include/w32api six.cpp -quiet -dumpbase six.cpp -mtune=generic -march=x86-64 -auxbase six -version -o /tmp/ccfHbtlL.s
GNU C++ (GCC) version 4.9.3 (x86_64-pc-cygwin)
        compiled by GNU C version 4.9.3, GMP version 6.0.0, MPFR version 3.1.2-p11, MPC version 1.0.3
warning: GMP header version 6.0.0 differs from library version 6.1.0.
warning: MPFR header version 3.1.2-p11 differs from library version 3.1.3.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "/usr/local/include"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-pc-cygwin/4.9.3/../../../../x86_64-pc-cygwin/include"
ignoring duplicate directory "/usr/lib/gcc/x86_64-pc-cygwin/4.9.3/../../../../x86_64-pc-cygwin/lib/../lib/../../include/w32api"
#include "..." search starts here:
#include <...> search starts here:
 /usr/lib/gcc/x86_64-pc-cygwin/4.9.3/include/c++
 /usr/lib/gcc/x86_64-pc-cygwin/4.9.3/include/c++/x86_64-pc-cygwin
 /usr/lib/gcc/x86_64-pc-cygwin/4.9.3/include/c++/backward
 /usr/lib/gcc/x86_64-pc-cygwin/4.9.3/include
 /usr/lib/gcc/x86_64-pc-cygwin/4.9.3/include-fixed
 /usr/include
 /usr/lib/gcc/x86_64-pc-cygwin/4.9.3/../../../../lib/../include/w32api
End of search list.
GNU C++ (GCC) version 4.9.3 (x86_64-pc-cygwin)
        compiled by GNU C version 4.9.3, GMP version 6.0.0, MPFR version 3.1.2-p11, MPC version 1.0.3
warning: GMP header version 6.0.0 differs from library version 6.1.0.
warning: MPFR header version 3.1.2-p11 differs from library version 3.1.3.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: a7b6fac296390f5db29d753ab65194e7
six.cpp:6:3: internal compiler error: Illegal instruction
   double f = 5.3;
   ^
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.

我刚刚开始用C ++编程,我很困惑为什么会这样。我也做过一些谷歌搜索,但没有发现任何相关内容。

2 个答案:

答案 0 :(得分:7)

您已获得internal compiler error: Illegal instruction,这意味着gcc编译器本身已失败。从警告来看,您似乎错误地安装了gcc工具链。尝试删除它并重新安装或升级。

答案 1 :(得分:4)

它失败的源代码部分在这里并不特别有趣,重要的一点是“内部编译器错误:非法指令”。

这意味着您的g ++副本是为较新的子体系结构构建的,而不是运行它的CPU。例如,SSE4指令是在2006年引入的,旧的CPU设计不支持它们。因为SSE用于浮点计算,所以找到浮点文字会触发错误是有道理的,但根本原因是指​​令集不匹配。

如果你检查.campoOpcional input { vertical-align: middle; } ,你可以找到你的CPU支持哪些指令集扩展,这将帮助你选择正确的g ++构建选项(无论你自己构建还是下载使用这些选项构建的包)

相关选项为the ones listed here,尤其是/proc/cpuinfo-march=-mfpmath=