开发者

Removing Flag in GCC using Pragma

I want to remove a compiler flag for a praticular file in my project. How t开发者_如何转开发o do this using #pragma?


Sorry that this is late, but I just ran into the same issue on my project.

I couldn't find a #pragma to modify the list of compiler flags, but I could use GNU Make's ability to modify make variables on a per-target basis.

One of my files was taking forever to compile with -fvar-tracking-assignments (which was added to -O2 a few releases back). I was looking for a way to turn that off for one file; after looking (in vain) for an appropriate pragma, I simply added this line to my makefile to modify CXXFLAGS when compiling and linking those specific files:

ObtuseObj.o ObtuseObjTest.o ObtuseObjTest : CXXFLAGS += -fno-var-tracking-assignments

Hopefully this will be helpful to others!


Only flags that control warnings can be overridden using #pragma, see the diagnostic pragmas documentation page.

For instance, you could do:

#pragma GCC diagnostic ignored "-Wformat"

To make GCC ignore the warnings generated by mismatched formatting strings.


I'm not sure if gcc has such pragmas. I can't find any on the gcc page for pragmas.

If you are asking a question related to gcc next time, tag it under gcc as well. I would tag it but I can't. Tagging under gcc would get you many more responses.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜