Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Makefile: Error1

Tags:

c

makefile

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?

like image 972
csgillespie Avatar asked Oct 27 '10 14:10

csgillespie


People also ask

What is error 1 in make?

make error 1 just means the build failed. A build step ( likely the link in your case ) returned an error code. the content of the brackets is the make target name. The reason should be in the lines preceding the make error in the build console (or build log).

How do I ignore an error in makefile?

To ignore errors in a recipe line, write a ' - ' at the beginning of the line's text (after the initial tab). The ' - ' is discarded before the line is passed to the shell for execution.

What does $< in makefile mean?

The $@ and $< are called automatic variables. The variable $@ represents the name of the target and $< represents the first prerequisite required to create the output file. For example: hello.o: hello.c hello.h gcc -c $< -o $@ Here, hello.o is the output file.

How do I clean my makefile?

The Cleanup Rule clean: rm *.o prog3 This is an optional rule. It allows you to type 'make clean' at the command line to get rid of your object and executable files. Sometimes the compiler will link or compile files incorrectly and the only way to get a fresh start is to remove all the object and executable files.


1 Answers

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.

like image 172
Alan Geleynse Avatar answered Oct 15 '22 21:10

Alan Geleynse