gpt4 book ai didi

C++ : multiple definition of `mainCRTStartup' error etc

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:47:57 24 4
gpt4 key购买 nike

所以我对 c++ 还很陌生,我用代码块编写了这个程序:

#include<iostream>

using namespace std;

int main()
{
cout << "Hello World!" << endl;
return 0;
}

当我构建并运行它时,出现错误。这是构建日志:

-------------- Build: Debug in HelloWorld (compiler: GNU GCC Compiler)---------------

mingw32-g++.exe -o bin\Debug\CPP_1.exe obj\Debug\main.o
obj\Debug\main.o:crt1.c:(.text+0x280): multiple definition of `mainCRTStartup'
c:/programfiles(x86)/codeblocks/mingw/bin/../lib/gcc/mingw32/4.7.1/../../../crt2.o:crt1.c:(.text+0x280): first defined here
obj\Debug\main.o:crt1.c:(.text+0x2a0): multiple definition of `WinMainCRTStartup'
c:/program files (x86)/codeblocks/mingw/bin/../lib/gcc/mingw32/4.7.1/../../../crt2.o:crt1.c:(.text+0x2a0): first defined here
obj\Debug\main.o:crt1.c:(.text+0x2c0): multiple definition of `atexit'
c:/program files (x86)/codeblocks/mingw/bin/../lib/gcc/mingw32/4.7.1/../../../crt2.o:crt1.c:(.text+0x2c0): first defined here
obj\Debug\main.o:crt1.c:(.text+0x2d0): multiple definition of `_onexit'
c:/program files (x86)/codeblocks/mingw/bin/../lib/gcc/mingw32/4.7.1/../../../crt2.o:crt1.c:(.text+0x2d0): first defined here
obj\Debug\main.o:cygming-crtbegin.c:(.text+0x2e0): multiple definition of `__gcc_register_frame'
c:/program files (x86)/codeblocks/mingw/bin/../lib/gcc/mingw32/4.7.1/crtbegin.o:cygming-crtbegin.c:(.text+0x0): first defined here
obj\Debug\main.o:cygming-crtbegin.c:(.text+0x32c): multiple definition of `__gcc_deregister_frame'
c:/program files (x86)/codeblocks/mingw/bin/../lib/gcc/mingw32/4.7.1/crtbegin.o:cygming-crtbegin.c:(.text+0x4c): first defined here
obj\Debug\main.o:crt1.c:(.bss+0x4): multiple definition of `_argc'
c:/program files (x86)/codeblocks/mingw/bin/../lib/gcc/mingw32/4.7.1/../../../crt2.o:crt1.c:(.bss+0x4):first defined here
obj\Debug\main.o:crt1.c:(.bss+0x0): multiple definition of `_argv'
c:/program files (x86)/codeblocks/mingw/bin/../lib/gcc/mingw32/4.7.1/../../../crt2.o:crt1.c:(.bss+0x0): first defined here
c:/program files (x86)/codeblocks/mingw/bin/../lib/gcc/mingw32/4.7.1/crtbegin.o:cygming-crtbegin.c:(.text+0x45): undefined reference to `_Jv_RegisterClasses'
collect2.exe: error: ld returned 1 exit status
Process terminated with status 1 (0 minute(s), 1 second(s))
13 error(s), 0 warning(s) (0 minute(s), 1 second(s))

我就是想不通为什么它不起作用。如果有人能帮助我,我将不胜感激。

最佳答案

我遇到了同样的问题 - 结果证明没有使用 -o name.exe 指定输出是一个糟糕的情况如果编译器在其移交的源文件中找到一个二进制文件,它不会抛出一个特定的错误 - 而是尝试将其用作某个库 - 当它发现两次出现 main 和 everything 时,这会出错。

关于C++ : multiple definition of `mainCRTStartup' error etc,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26412974/

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