I have the following Makefile:
all: test.c test1.c
gcc -o test test.c -lm
gcc -o test1 test1.c
./test 1000 input.txt
./test 1000 input.txt make: *** [run] Error 255
If you want to run a command after a successful build, use separate prerequisites as follows:
all: test test1 run_test: test ./test 1000 input.txt test: test.c gcc -o test test.c -lm test1: test1.c gcc -o test1 test1.c
Makefile doesn't check if the build was successful. So it is possible that the
test executable is not available when you are running
./test 1000 input.txt.
Another way is to chain the commands using the shell AND operator:
all: test.c test1.c gcc -o test test.c -lm && ./test 1000 input.txt gcc -o test1 test1.c
But the preferred way is definitely to use separate prerequisites (targets).
As mentioned, you should always use
-Wall compiler option!