How to selectively disable -Werror using #pragma with gcc

In my search for a free warning app, I started using -Werror so gcc treats all warnings as errors.

This is really very useful, because sometimes I missed one or two (serious) warnings in a large build release. Unfortunately, my project uses sqlite3, which contains many warnings that, as indicated on the sqlite website, cannot be fixed (they do not want to delete).

I was wondering if there is a way to use some # pragma that I can put in the sqlite3.c file to tell gcc to stop treating warnings as an error only for this file.

I tried:

#pragma GCC diagnostic ignored "-Werror" 

without success I also tried to list one after the other warnings that cause problems with:

 #pragma GCC diagnostic ignored "-Wextra" #pragma GCC diagnostic ignored "-Wfloat-equal" #pragma GCC diagnostic ignored "-Wundef" ... 

... Unfortunately, there are some warnings that cannot be completely disabled (i.e., initialization discards qualifiers from the target pointer type).

Any idea / suggestions?

+5
source share
1 answer

You can add an additional rule to your Makefile for sqlite3.c , which compiles the file without -Werror or without any warnings at all. In conventional agreements, it may be sufficient:

 sqlite3.o: sqlite3.c $(CC) $(CFLAGS) -w -c sqlite3.c 
+2
source

Source: https://habr.com/ru/post/1234789/


All Articles