11

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?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
fabrizi0
  • 673
  • 1
  • 6
  • 14
  • Related: https://stackoverflow.com/questions/32049296/how-to-disable-all-warnings-using-pragma-directives-in-gcc https://stackoverflow.com/questions/58956003/how-to-enable-werror-using-gcc-pragma https://stackoverflow.com/questions/3378560/how-to-disable-gcc-warnings-for-a-few-lines-of-code – Jerry Jeremiah May 12 '21 at 21:17

1 Answers1

1

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
fuz
  • 88,405
  • 25
  • 200
  • 352
  • I thought of that, unfortunately I'm using autoconf/automake... and it's already quite messy. Warnings (and -Werror) are selected during ./configure so I can enable it when building a debug version for a host target. Warnings are then disabled when building for the target (embedded Linux) system. – fabrizi0 Oct 29 '15 at 13:10
  • @fabrizi0 It should be no problem to add an extra rule for a specific file with `automake`. I'm not experienced with it though, you may need to consult its documentation to find out how exactly to do this. Please also considder tagging this as [tag:automake] and editing your question to point out that you want a way to disable `-Werror` or supply `-w` for one file if you'd like to receive an answer along that line. – fuz Oct 29 '15 at 13:14
  • 1
    FUZxxl: unfortunately as I suspected automake does not support per-object flag only per-target flags). As mentioned also in this post: http://stackoverflow.com/questions/149324/setting-per-file-flags-with-automake. If I don't get any good way to do it on a per-file, I will have to create a sqlite lib and link my app against it. – fabrizi0 Oct 29 '15 at 17:48