0

我的一个朋友查看了我的代码并提出了一些改进建议。这些建议应该可行,而且我们已经解决了代码本身的所有错误,但是在尝试编译一个基本的 int main() 时,它会引发一堆关于其自身库中某些内容的错误。唯一改变的是我们细化了代码,以减少重复的语句,并且还使用布尔值而不是其他东西。

这是现在的代码:http: //pastebin.com/nG0Dr4h0

以下是错误:

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
4

2 回答 2

0

您要求 gcc 编译两个源,其中一个是 exe(已编译项目)。因此,它检测到很多重复,因为 exe 已经包含了它应该链接到中间对象的大部分内容。

将调用更改为

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

告诉 GCC 输出文件是 exe,它将把它从输入源中删除。然后它不会尝试将调用实现添加到已经具有实现的一组输入中。

于 2013-11-01T17:49:54.880 回答
0

将 -c 添加到输入源文件。当 -c 选项未用于编译器标志时,我们会收到此错误。像这样-

gcc -Werror -Wall -c jumpYear.c jumpYear.exe

或者

gcc -c jumpYear.c -Werror -Wall jumpYear.exe

于 2016-02-02T14:34:18.357 回答