c++ - G++ 将 float 视为非法指令

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

在我的文件“six.cpp”中,我尝试打印一个 float ,但编译器一直抛出错误。这是文件“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++ 编程,我很困惑为什么会这样。我也进行了一些谷歌搜索,但没有找到任何相关信息。

最佳答案

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

关于c++ - G++ 将 float 视为非法指令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41384730/

相关文章:

rust - 是否有推荐的方法将 `if let` 与浮点值一起使用?

c++ - 具有可变模板参数的成员函数的显式特化

c - 为什么 stdarg.h 中的第一个参数是寄存器?

linux - gcc 链接错误

使用 gcc 的 c++ 命令行编译

c# - 我怎样才能输出足够精确的值来揭示 Debug 和 Release 之间的这种算术差异?

floating-point - 为什么为 NaN 保留这么多 float/double 值?

c++ - 我应该返回一个迭代器还是一个指向 STL 容器中元素的指针?

c++ - 在没有 Malloc/New 或 Free/Delete 的情况下管理连续的内存块

c++ - C++ 中的 vector 和 map