C ++:`mainCRTStartup'的多重定义错误等

时间:2014-10-16 20:07:23

标签: c++ gcc mingw codeblocks

所以我对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))

我根本无法弄清楚它为什么不起作用。如果有人能帮助我,我会非常感激。

1 个答案:

答案 0 :(得分:1)

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