0
我最近決定開始編寫符合標準的C++,而不是使用Turbo-C++,因此我在Windows 7上下載了cygwin並安裝了g ++。我試圖運行一個Hello World程序:g ++(cygwin)中的多重聲明錯誤
#include<iostream>
using namespace std;
int main()
{
cout << "Hello World!" << endl;
return 0;
}
和類型此Cygwin中:
g++ test.cpp -o test
g++ test
希望我做沒事,我按下回車找到我的心臟由難以理解這個巨大的破壁文字:
$ g++ test.exe
test.exe: In function `mainCRTStartup':
/usr/src/debug/cygwin-1.7.27-2/winsup/cygwin/crt0.c:23: multiple definition of `mainCRTStartup'
/usr/lib/gcc/x86_64-pc-cygwin/4.8.2/../../../../lib/crt0.o:/usr/src/debug/cygwin-1.7.27-2/winsup/cygwin/crt0.c:23: first defined here
test.exe: In function `mainCRTStartup':
/usr/src/debug/cygwin-1.7.27-2/winsup/cygwin/crt0.c:23: multiple definition of `WinMainCRTStartup'
/usr/lib/gcc/x86_64-pc-cygwin/4.8.2/../../../../lib/crt0.o:/usr/src/debug/cygwin-1.7.27-2/winsup/cygwin/crt0.c:23: first defined here
test.exe:cygming-crtbegin.c:(.text+0x60): multiple definition of `__gcc_register_frame'
/usr/lib/gcc/x86_64-pc-cygwin/4.8.2/crtbegin.o:cygming-crtbegin.c:(.text+0x10): first defined here
test.exe:cygming-crtbegin.c:(.text+0xc0): multiple definition of `__gcc_deregister_frame'
/usr/lib/gcc/x86_64-pc-cygwin/4.8.2/crtbegin.o:cygming-crtbegin.c:(.text+0x70): first defined here
test.exe:crt0.c:(.text+0x50): multiple definition of `.weak._Jv_RegisterClasses.__gcc_register_frame'
/usr/lib/gcc/x86_64-pc-cygwin/4.8.2/crtbegin.o:cygming-crtbegin.c:(.text+0x0): first defined here
test.exe:cygming-crtend.c:(.idata+0x178): multiple definition of `__imp__ZSt4cout'
test.exe:cygming-crtend.c:(.idata+0x178): first defined here
/usr/lib/gcc/x86_64-pc-cygwin/4.8.2/crtbegin.o:cygming-crtbegin.c:(.text+0x35): undefined reference to `_Jv_RegisterClasses'
/usr/lib/gcc/x86_64-pc-cygwin/4.8.2/crtbegin.o:cygming-crtbegin.c:(.text+0x35): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `_Jv_RegisterClasses'
/usr/lib/gcc/x86_64-pc-cygwin/4.8.2/../../../../x86_64-pc-cygwin/bin/ld: /usr/lib/gcc/x86_64-pc-cygwin/4.8.2/crtbegin.o: bad reloc address 0x0 in section `.pdata'
collect2: error: ld returned 1 exit status
請問有人請看看這個,並告訴我我做錯了什麼?
爲什麼'g ++ test.exe'?你不想只用'。/ test'來執行它嗎? –
我不保證這會解決它,但是嘗試編譯爲'test.o'而不是'test',然後使用'g ++ test.o'而不是'g ++ test'鏈接。 –
如果你沒有命名你的程序測試會更好。稱之爲ctest或cpptest。測試是對unix的一個命令。如果你只是輸入test而不是./test,它將不會輸出任何東西,你會在圈子裏跑來跑去試圖弄清楚爲什麼你的程序不打印任何東西。 – cup