gpt4 book ai didi

c - 在 GCC 中使用 -Wall -Wextra 并出现错误

转载 作者:太空宇宙 更新时间:2023-11-04 08:54:01 51 4
gpt4 key购买 nike

当我使用 GCC 编译并且不使用 -Wall-Wextra 时,我不确定为什么会收到这些错误程序编译正常。但是,当我使用标志 -Wall-Wextra 时,我收到编译错误。

这是我运行的测试程序:

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

int main(void)
{
return 0;
}

...这是我从中得到的错误:

/home/definity/Desktop/Cloud/code/funcptr: In function `_fini':
(.fini+0x0): multiple definition of `_fini'
/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../x86_64-linux-gnu/crti.o:(.fini+0x0): first defined here
/home/definity/Desktop/Cloud/code/funcptr: In function `data_start':
(.data+0x0): multiple definition of `__data_start'
/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../x86_64-linux-gnu/crt1.o:(.data+0x0): first defined here
/home/definity/Desktop/Cloud/code/funcptr: In function `data_start':
(.data+0x8): multiple definition of `__dso_handle'
/usr/lib/gcc/x86_64-linux-gnu/4.7/crtbegin.o:(.data+0x0): first defined here
/home/definity/Desktop/Cloud/code/funcptr:(.rodata+0x0): multiple definition of `_IO_stdin_used'
/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../x86_64-linux-gnu/crt1.o:(.rodata.cst4+0x0): first defined here
/home/definity/Desktop/Cloud/code/funcptr: In function `_start':
(.text+0x0): multiple definition of `_start'
/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../x86_64-linux-gnu/crt1.o:(.text+0x0): first defined here
/home/definity/Desktop/Cloud/code/funcptr: In function `main':
/home/definity/Desktop/Cloud/code/funcptr.c:35: multiple definition of `main'
/tmp/cctHUnUj.o:/home/definity/Desktop/Cloud/code/funcptr.c:9: first defined here
/home/definity/Desktop/Cloud/code/funcptr: In function `_init':
(.init+0x0): multiple definition of `_init'
/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../x86_64-linux-gnu/crti.o:(.init+0x0): first defined here
/usr/lib/gcc/x86_64-linux-gnu/4.7/crtend.o:(.tm_clone_table+0x0): multiple definition of `__TMC_END__'
/home/definity/Desktop/Cloud/code/funcptr:(.data+0x10): first defined here
/usr/bin/ld: error in /home/definity/Desktop/Cloud/code/funcptr(.eh_frame); no .eh_frame_hdr table will be created.
collect2: error: ld returned 1 exit status
[Finished in 0.1s with exit code 1]

...我无法解释这些错误。谁能解释为什么会出现这些错误,以及我可以做些什么来防止这种情况在未来发生?

最佳答案

基于 this link :

    -Wall
This enables all the warnings about constructions that some users consider
questionable, and that are easy to avoid (or modify to prevent the warning), even in
conjunction with macros. This also enables some language-specific warnings described in C++ Dialect Options and Objective-C and Objective-C++ Dialect Options.

-Wall turns on the following warning flags:

-Waddress
-Warray-bounds (only with -O2)
-Wc++11-compat
-Wchar-subscripts
-Wenum-compare (in C/ObjC; this is on by default in C++)
-Wimplicit-int (C and Objective-C only)
-Wimplicit-function-declaration (C and Objective-C only)
-Wcomment
-Wformat
-Wmain (only for C/ObjC and unless -ffreestanding)
-Wmaybe-uninitialized
-Wmissing-braces (only for C/ObjC)
-Wnonnull
-Wparentheses
-...

Note that some warning flags are not implied by -Wall. Some of them warn about
constructions that users generally do not consider questionable, but which occasionally you might wish to check for; others warn about constructions that are necessary or hard to
avoid in some cases, and there is no simple way to modify the code to suppress the warning.
Some of them are enabled by -Wextra but many of them must be enabled individually.

关于c - 在 GCC 中使用 -Wall -Wextra 并出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18264853/

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