So I'm fairly new to c++, and I have this program written in code blocks:
#include<iostream>
using namespace std;
int main()
{
cout << "Hello World!" << endl;
return 0;
}
when I build it an run it, I get an error. Here is the build log:
-------------- 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))
I simply cannot figure out why it isn't working. If anyone could help me out, I would be very appreciative.
I had the same problem- and it turned out to be a bad case of not specifying the output with -o name.exe If the compiler finds a binary in its handed over source files it doesent throw a specific error - and instead trys to use it as some library- which goes wrong, when it finds two occurances of main and everything.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With