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?
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).
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With