gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 00:36:36 28 4
gpt4 key购买 nike

我最近决定开始编写符合标准的 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

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

最佳答案

不需要g++ test命令

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

运行它

关于c++ - g++ (cygwin) 中的多重声明错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20664577/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com