2016-12-29 85 views
2

在我的文件「six.cpp」中,我嘗試打印一個浮點數,但編譯器一直拋出一個錯誤。下面是該文件「six.cpp」:G ++將float看作非法指令

#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++編程,而且我很困惑,爲什麼會發生這種情況。我也做了一些谷歌搜索,並沒有發現任何關於此。

+1

1.爲什麼您的代碼鏈接到GMP和MPFR? AFAIK,這些是多個精確庫,我看不到你需要它們的地方。 2.顯然,GMP和MPFR的標題與庫不匹配。 3.你似乎遇到* internal *編譯器錯誤。這可能是你的設置有問題。刪除所有內容並正確安裝一個匹配的cygwin。 –

+1

@Rudy:GNU編譯器集合在內部使用這些集合。 –

+0

@BenVoigt:好的,我不知道。感謝您的提醒。 –

回答

7

你有一個internal compiler error: Illegal instruction,這意味着gcc編譯器本身失敗。從警告中可以看出您錯誤地安裝了gcc工具鏈。嘗試刪除它並重新安裝或升級。

4

其中失敗的部分源代碼在這裏並不特別有趣,重要的是「內部編譯器錯誤:非法指令」。

這意味着您的g ++副本是爲比您正在運行它的CPU更新的子架構而構建的。例如,2006年推出了SSE4指令,舊款CPU設計不支持它們。因爲SSE用於浮點計算,所以找到浮點文字觸發錯誤是有意義的,但根本原因是指​​令集不匹配。

如果您檢查/proc/cpuinfo,您可以找到CPU支持哪些指令集擴展,這將幫助您選擇正確的g ++構建選項(無論是自己構建還是下載使用這些選項構建的包)。

相關選項爲the ones listed here,特別是-march=-mfpmath=-m(no)fused-madd