1

How can I know the return value of gcc?

For example, I have one c file, test.c, and I simply run gcc test.c in terminal. It can report if current compile meet some errors, but how can I know the return value of this time compile process of gcc?

Now I know 1 means has error, but 0 will return not only warning but also compile OK, how can I if there is error. If I use -Werror, it may stop compile, I don't want to stop compile

some_other_guy
  • 3,364
  • 4
  • 37
  • 55
How Chen
  • 1,340
  • 2
  • 17
  • 37
  • Related: [How to check if gcc has failed](http://stackoverflow.com/questions/1024525/how-to-check-if-gcc-has-failed-returned-a-warning-or-succeeded-in-bash) – Sjoerd Sep 04 '12 at 08:57
  • I add some warning in code and use gcc to compile:`>gcc -Wall test.c test.c:3:6: warning: return type of ‘main’ is not ‘int’ [-Wmain] test.c: In function ‘main’: test.c:5:6: warning: unused variable ‘noUse’ [-Wunused-variable]` and I use `echo $?`., it return as `>echo $? 0` – How Chen Sep 04 '12 at 09:09

1 Answers1

6

The return variable is in the shell variable $?.

> gcc bla.c
> echo $?
0

Edit: on windows it is in %errorlevel%.

Community
  • 1
  • 1
Sjoerd
  • 74,049
  • 16
  • 131
  • 175
  • 1
    I test it, but it seems warning will return 0 as well, I just add `-Wall` when use gcc and add an unused value in my source code, gcc generate warning but return 0 – How Chen Sep 04 '12 at 09:04