tags:

views:

34

answers:

3
+3  Q: 

Makefile: Error1

I have a very simple c programme:

int main()
{
  return(1);
}

and a simple Makefile:

all:
    gcc -ansi -pedantic -o tmp tmp.c
    ./tmp

However, when I type make I get the following error message:

$ make
gcc -ansi -pedantic -o tmp tmp.c
./tmp
make: *** [all] Error 1

What obvious thing am I missing?

+3  A: 

You're returning an error code of 1 from your application. It's Make's job to report this as an error!

Oli Charlesworth
+1  A: 

This is because your program is returning 1.

Makes does the compilation using gcc, which goes fine (returns 0) so it proceeds with the execution, but your program return a non-zero value, so make reports this as an error.

A program on successful completion should return 0 and return a non-zero value otherwise.

codaddict
+8  A: 

Make exits with an error if any command it executes exits with an error.

Since your program is exiting with a code of 1, make sees that as an error, and then returns the same error itself.

You can tell make to ignore errors by placing a - at the beginning of the line like this:

-./tmp

You can see more about error handling in makefiles here.

Alan Geleynse
I knew it was going to be obvious. Thanks (to everyone) for the very quick answers
csgillespie
+1, for the ignore part.
codaddict
Yeah I ran into this exact error a few months ago. I had to look up the syntax again to ignore errors though, its not something I use enough to remember.
Alan Geleynse