g ++中的多重声明错误(cygwin)

时间:2013-12-18 17:27:12

标签: c++ g++ cygwin

我最近决定开始编写符合标准的C ++,而不是使用Turbo-C ++,因此我在Windows 7上下载了cygwin并安装了g ++。我试图运行一个hello world程序:

#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

有人可以看看这个并告诉我我做错了吗?

1 个答案:

答案 0 :(得分:3)

无需g++ test命令

命令g++ test.cpp -o test将编译并链接您的代码。您可以使用./test.exe

运行它