Dinesh
Dinesh

Reputation: 111

Removing Flag in GCC using Pragma

I want to remove a compiler flag for a praticular file in my project. How to do this using #pragma?

Upvotes: 0

Views: 2487

Answers (3)

AnthonyFoiani
AnthonyFoiani

Reputation: 514

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!

Upvotes: 3

unwind
unwind

Reputation: 400009

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.

Upvotes: 2

vpit3833
vpit3833

Reputation: 7961

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.

Upvotes: 0

Related Questions