cwindowsgcc

GCC won't compile, gives loads of errors from its own libraries on even basic code


A friend of mine looked over my code and gave some suggestions for improvements. These suggestions should work, and we've ironed out all the bugs in the code itself, but upon trying to compile even a basic int main(), it throws up a bunch of errors regarding something in its own libraries. The only thing that changed is we refined the code down so that there were less repeated statements and also used booleans instead of other stuff.

Here's the code right now: http://pastebin.com/nG0Dr4h0

Here are the errors:

E:\Utils\compile\files>gcc -Werror -Wall leapYear.c leapYear.exe
leapYear.exe:crt1.c:(.text+0x280): multiple definition of `mainCRTStartup'

e:/utils/compile/c/gcc/bin/../lib/gcc/mingw32/4.7.1/../../../crt2.o:crt1.c:(.text+0x280): first defined here
leapYear.exe:crt1.c:(.text+0x2a0): multiple definition of `WinMainCRTStartup'

e:/utils/compile/c/gcc/bin/../lib/gcc/mingw32/4.7.1/../../../crt2.o:crt1.c:(.text+0x2a0): first defined here
leapYear.exe:crt1.c:(.text+0x2c0): multiple definition of `atexit'

e:/utils/compile/c/gcc/bin/../lib/gcc/mingw32/4.7.1/../../../crt2.o:crt1.c:(.text+0x2c0): first defined here
leapYear.exe:crt1.c:(.text+0x2d0): multiple definition of `_onexit'

e:/utils/compile/c/gcc/bin/../lib/gcc/mingw32/4.7.1/../../../crt2.o:crt1.c:(.text+0x2d0): first defined here
leapYear.exe:cygming-crtbegin.c:(.text+0x2e0): multiple definition of `__gcc_register_frame'

e:/utils/compile/c/gcc/bin/../lib/gcc/mingw32/4.7.1/crtbegin.o:cygming-crtbegin.c:(.text+0x0): first defined here
leapYear.exe:cygming-crtbegin.c:(.text+0x32c): multiple definition of `__gcc_deregister_frame'

e:/utils/compile/c/gcc/bin/../lib/gcc/mingw32/4.7.1/crtbegin.o:cygming-crtbegin.c:(.text+0x4c): first defined here
leapYear.exe:leapYear.c:(.text+0x334): multiple definition of `main'

C:\Users\[REDACTED]\AppData\Local\Temp\ccKNWKLb.o:leapYear.c:(.text+0x72): first defined here
leapYear.exe:crt1.c:(.bss+0x4): multiple definition of `_argc'

e:/utils/compile/c/gcc/bin/../lib/gcc/mingw32/4.7.1/../../../crt2.o:crt1.c:(.bss+0x4): first defined here
leapYear.exe:crt1.c:(.bss+0x0): multiple definition of `_argv'

e:/utils/compile/c/gcc/bin/../lib/gcc/mingw32/4.7.1/../../../crt2.o:crt1.c:(.bss+0x0): first defined here

e:/utils/compile/c/gcc/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

Solution

  • You are asking gcc to compile two sources, one of which is an exe (already compiled item). As such, it detect a lot of duplication, as the exe already contains much of what it should link into the intermediary objects.

    Change the invocation to

    E:\Utils\compile\files>gcc -Werror -Wall leapYear.c -o leapYear.exe
    

    To tell GCC that the output file is the exe, which will take it off of the input sources. Then it won't be trying to add in call implementations to a set of inputs that already has the implementations.