使用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

一切正常!
本文详细解析了在使用Makefile时遇到的非零退出错误,通过修改C程序的返回值,成功解决了Makefile运行失败的问题。文章提供了具体的代码示例和Makefile配置,帮助读者理解错误原因及解决方案。

被折叠的 条评论
为什么被折叠?



