简体   繁体   English

gcc disable - 特定文件/文件夹的标志

[英]gcc disable -Wall flag for specific files/folders

I have some open source library files in my project (eg: http://nothings.org/stb_vorbis/stb_vorbis.c ). 我的项目中有一些开源库文件(例如: http//nothings.org/stb_vorbis/stb_vorbis.c )。 -Wall option is enabled in my Android.mk file. -Wall选项在我的Android.mk文件中启用。 During compilation several warnings are generated in stb_vorbis.c. 在编译期间,stb_vorbis.c中会生成几个警告。

warning: unused variable <var>
warning: statement with no effect
warning: <var> defined but not used
warning: <var> may be used uninitialized in this function

For some reason I do not want to modify stb_vorbis.c but still want the -Wall option to be available for my own source files. 出于某种原因,我不想修改stb_vorbis.c但仍希望-Wall选项可用于我自己的源文件。 Is there any way to disable -Wall option for specific files/folder ? 有没有办法禁用特定文件/文件夹的-Wall选项?

Is there any way to disable -Wall option for specific files/folder ? 有没有办法禁用特定文件/文件夹的-Wall选项?

I do not believe there is any gcc option that could be used to achieve this. 我不相信有任何gcc选项可用于实现这一目标。 You need to change your Makefile that you used to compile the problematic source files. 您需要更改用于编译有问题的源文件的Makefile。

You could do something like 你可以做点什么

CFLAGS:=$(filter-out -Wall, $(CFLAGS))

in the Makefile for stb_vorbis , if your make supports filter-out function. stb_vorbis的Makefile中,如果你的make支持filter-out功能。

Also you could write a specific rule for that stb_vorbis.c : 您还可以为该stb_vorbis.c编写特定规则:

STB_VOBIS_CFLAGS:=$(filter-out -Wall, $(CFLAGS))
stb_vorbis.o: stb_vorbis.c ...
        $(CC) $(STB_VOBIS_CFLAGS) -o $@ -c $<

Although there's no way to turn off -Wall with one option, you can turn off specific warnings in GCC, using the -Wno-* for warning * . 虽然没有办法通过一个选项关闭-Wall ,但您可以在GCC中关闭特定警告,使用-Wno-*作为警告* So, for example, to suppress the unused variable warning you can add -Wno-unused-variable . 因此,例如,要禁止使用未使用的变量警告,可以添加-Wno-unused-variable See http://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html for more information on different warning options. 有关不同警告选项的更多信息,请参见http://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html

So for example you could use target-specific variables, like: 例如,您可以使用特定于目标的变量,例如:

stb_vorbis.c: CFLAGS += -Wno-unused-variable

Using target-specific variables you can append the -w option to inhibit all warning messages for stb_vorbis.c file: 使用特定于目标的变量,您可以附加-w选项以禁止stb_vorbis.c文件的所有警告消息:

stb_vorbis.o: CFLAGS += -w

or for an entire directory: 或者对于整个目录:

third_party/%.o: CFLAGS += -w

A general rule of thumb is that if you have two or more mutually exclusive options, gcc will generally take later options over earlier ones. 一般的经验法则是,如果您有两个或更多互斥选项,gcc通常会比以前的选项采用更晚的选项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM