126

The problem is that the same code that compiles well on Windows, is unable to compile on Ubuntu. Every time I get this error:

cc1: warnings being treated as errors

Now, it's big code base and I don't like fix all the warnings.

Is there a way I can compile successfully in spite of the warnings?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Saurabh Verma
  • 6,328
  • 12
  • 52
  • 84
  • 2
    I strongly suggest trying to fix the warnings. If not immediately, then gradually. Once you get rid of `-Werror`, you can add it back on a per-directory basis, after you've removed warnings. – ugoren Jul 19 '12 at 13:04
  • Even if you do compile successfully, it might not run the way you expect. I've had a few people write code that works just fine on Windows but crashes immediately on Linux. – Dennis Meng Jul 19 '12 at 16:39
  • Thanks everyone for their useful comments and answers. According to the requirement it seems that I have to fix all the warnings, which I have started. But now the warning I'm getting is from sqlite3.c: Assuming signed overflow does not occur when assuming that (X - c) <= X is always true – Saurabh Verma Jul 20 '12 at 07:22

7 Answers7

101

Sure, find where -Werror is set and remove that flag. Then warnings will be only warnings.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Daniel Fischer
  • 181,706
  • 17
  • 308
  • 431
  • 4
    Thanks Daniel, but there is no -Werror flag set in my project. Should I look for it somewhere else ? – Saurabh Verma Jul 19 '12 at 12:53
  • 20
    Somewhere it must be set, by default warnings aren't treated as errors by any compiler I know. If you can't find it, you can try overriding it with `-Wno-error`, as nightcracker suggested. That should work unless the `-Werror` is passed after the flags you set in `CFLAGS` in the makefile. – Daniel Fischer Jul 19 '12 at 12:59
46

You can make all warnings being treated as such using -Wno-error. You can make specific warnings being treated as such by using -Wno-error=<warning name> where <warning name> is the name of the warning you don't want treated as an error.

If you want to entirely disable all warnings, use -w (not recommended).


Source: 3.8 Options to Request or Suppress Warnings

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
orlp
  • 112,504
  • 36
  • 218
  • 315
23

Solution:

CFLAGS=-Wno-error ./configure
Zibri
  • 9,096
  • 3
  • 52
  • 44
15

Remove -Werror from your Make or CMake files, as suggested in this post.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Andrea Araldo
  • 1,332
  • 14
  • 20
4

The -Wall and -Werror compiler options can cause it. Please check if those are used in compiler settings.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Marlab
  • 41
  • 3
4

If you are compiling the Linux kernel:

For example, if you want to disable the warning that is "unused-but-set-variable" been treated as error. You can add a statement:

KBUILD_CFLAGS += $(call cc-option,-Wno-error=unused-but-set-variable,)

in your Makefile.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
3

Thanks for all the helpful suggestions. I finally made sure that there were no warnings in my code, but again was getting this warning from SQLite 3:

Assuming signed overflow does not occur when assuming that (X - c) <= X is always true

which I fixed by adding the CFLAG -fno-strict-overflow.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Saurabh Verma
  • 6,328
  • 12
  • 52
  • 84
  • Many warnings are there to point you to problematic constructs in your code. Disabling them will let you move on in the short perspective, but you'll never know if these issues will come back to haunt you in the long run. – Benjamin Bannier Jul 20 '12 at 11:00
  • 1
    Yes, you are right. I had meant that I've made sure that my code is warning free (I've not disabled all the warnings) – Saurabh Verma Jul 20 '12 at 14:26