Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to selectively disable -Werror using #pragma with gcc

Tags:

c

sqlite

gcc

In my quest to a warning-free application, I have started to use -Werror to tell GCC to treat all the warnings as errors.

This is indeed very helpful as sometimes I missed one or two (serious) warnings in a large build output. Unfortunately, my project uses SQLite 3 that contains many warnings that, as stated on the SQLite web site, cannot be eliminated (they don't want to remove).

I was wondering if there's a way to use some #pragma I can place in the sqlite3.c file to tell GCC to stop treating warnings as error only for that file.

I tried with:

#pragma GCC diagnostic ignored "-Werror"

with no success.

I have also tried to list one by one the 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 turned off entirely (i.e., initialization discards qualifiers from pointer target type).

What can I do?

like image 559
fabrizi0 Avatar asked Oct 29 '15 12:10

fabrizi0


1 Answers

You could add an extra rule to your Makefile for sqlite3.c that compiles the file without -Werror or without any warnings at all. With the usual conventions, something like this might suffice:

sqlite3.o: sqlite3.c
    $(CC) $(CFLAGS) -w -c sqlite3.c
like image 178
fuz Avatar answered Nov 05 '22 09:11

fuz