Home » Errors & Failures » How to resolve “cc1: all warnings being treated as errors” ?

How to resolve “cc1: all warnings being treated as errors” ?

If you are compiling some C program or open source package using Makefile which is written by someone else, there are chances you may encounter error as “cc1: all warnings being treated as errors” and you will not be able to compile the program or package.

So this error, tells us that there are some “warnings” in the program and those are getting considered as “errors” forcing you to fist fix those errors to proceed with the compilation, so there are following ways to proceed,

1. Its always better to resolve those errors if you have time.
2. If you dont have time, and can ignore “warnings” for a while, just search the code as,

 grep -r Werror * 

to identify which Makefile is enabling “Werror”
3. remove/delete this completely from that Makefile or Change it to “-wno-error”
4. save this makefile and recompile the code. This will show the warnings but will not stop compilation reporting those as errors.

Now, let me show how this works with the simple program.

Create a helloworld.c as below,

#include <stdio.h>

int main(int argc, char **argv) {
        void *p;
        printf("Hello World\n");
        p = 10;
        return 0;
}

Above program purposefully creates a warning in which we are trying to set integer number to void pointer.
Now, lets try to compile this program as it is,

$ gcc helloworld.c
helloworld.c: In function ‘main’:
helloworld.c:6:4: warning: assignment makes pointer from integer without a cast [-Wint-conversion]
  p = 10;
    ^

This actually went ahead to create a.out by showing one warning as above. But in case of big programs, we dont know how many actual warnings will be,
hence we will enable “show all warnings” macro “-Wall” during command line,

 $ gcc helloworld.c -Wall
helloworld.c: In function ‘main’:
helloworld.c:6:4: warning: assignment makes pointer from integer without a cast [-Wint-conversion]
  p = 10;
    ^
helloworld.c:4:8: warning: variable ‘p’ set but not used [-Wunused-but-set-variable]
  void *p;
        ^

Now, lets force all those warnings as errors, so someone should not be able to create executable without resolving this errors,

$ gcc helloworld.c -Wall -Werror
helloworld.c: In function ‘main’:
helloworld.c:6:4: error: assignment makes pointer from integer without a cast [-Werror=int-conversion]
  p = 10;
    ^
helloworld.c:4:8: error: variable ‘p’ set but not used [-Werror=unused-but-set-variable]
  void *p;
        ^
cc1: all warnings being treated as errors

And now the ultimate workaround to temporarily proceed with creating executable without resolving these error, if you just need to get it compiled somehow since your boss has asked to get it done asap. 🙂

$ gcc -o helloworld helloworld.c -Wall -Wno-error 
helloworld.c: In function ‘main’:
helloworld.c:6:4: warning: assignment makes pointer from integer without a cast [-Wint-conversion]
  p = 10;
    ^
helloworld.c:4:8: warning: variable ‘p’ set but not used [-Wunused-but-set-variable]
  void *p;
        ^

And this is how it will create the executable without resolving this warnings.

$ ls
helloworld  helloworld.c

Same things can be done in Makefiles by passing CFLAGS=-Wno-error & CFLAGS=-Werror


Subscribe our Rurban Life YouTube Channel.. "Rural Life, Urban LifeStyle"

Leave a Comment