如何为特定目录或文件启用特定gcc警告? [重复]

时间:2022-05-26 05:07:19

Possible Duplicate:
Selectively disable GCC warnings for only part of a translation unit?

可能重复:有选择地仅对部分翻译单元禁用GCC警告?

How to enable a specific gcc warnings for a specific directory or file ?

如何为特定目录或文件启用特定gcc警告?

I want to enable -Wsign-conversion for my own files not for any other system headers

我想为我自己的文件启用-Wsign-conversion而不是任何其他系统头

2 个解决方案

#1


3  

This line should do it: (see here)
#pragma GCC diagnostic warning "-Wsign-conversion"

这行应该这样做:(见这里)#pragma GCC诊断警告“-Wsign-conversion”

Put it in the affected files or in a header that is included in all you files

将其放在受影响的文件中或包含在所有文件中的标题中

#2


1  

If you want to do it outside of your source file, then you need to reference your build system. E.g. in make you can always specify a direct target in the Makefile:

如果要在源文件之外执行此操作,则需要引用构建系统。例如。在make中,您始终可以在Makefile中指定直接目标:

foo.o: foo.c
    $(CC) -o $> -Wsign-conversion $<

This will take precedence to a general .c->.o rule as it is more more specific.

这将优先于一般的.c - > .o规则,因为它更具体。

Other build systems have other methods of achieving the same rule.

其他构建系统具有实现相同规则的其他方法。

In short, your question is really about your build system, and not about gcc.

简而言之,您的问题实际上是关于您的构建系统,而不是关于gcc。

#1


3  

This line should do it: (see here)
#pragma GCC diagnostic warning "-Wsign-conversion"

这行应该这样做:(见这里)#pragma GCC诊断警告“-Wsign-conversion”

Put it in the affected files or in a header that is included in all you files

将其放在受影响的文件中或包含在所有文件中的标题中

#2


1  

If you want to do it outside of your source file, then you need to reference your build system. E.g. in make you can always specify a direct target in the Makefile:

如果要在源文件之外执行此操作,则需要引用构建系统。例如。在make中,您始终可以在Makefile中指定直接目标:

foo.o: foo.c
    $(CC) -o $> -Wsign-conversion $<

This will take precedence to a general .c->.o rule as it is more more specific.

这将优先于一般的.c - > .o规则,因为它更具体。

Other build systems have other methods of achieving the same rule.

其他构建系统具有实现相同规则的其他方法。

In short, your question is really about your build system, and not about gcc.

简而言之,您的问题实际上是关于您的构建系统,而不是关于gcc。