使用Makefile 运行当前目录下生成的可执行文件时出现:Makefile:3: recipe for target 'test' failed
类似的错误。该问题很大可能是程序运行结束后返回给make 的值是非0导致的结果。
1.test.c
#include<stdio.h>
int main(){
printf("----------------\n");
return 2;
}
2.Makefile
target : prerequests
[tab] command
命令的前面一定要是tab键
test : test.c
clang test.c -o test
./test
命令行运行:make test
3.修改test.c 程序运行结束返回值
#include<stdio.h>
int main(){
printf("----------------\n");
return 0;
}
4.命令行运行:make test
一切正常!