Makefile:xxx: recipe for target 'xxx' failed

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

使用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
在这里插入图片描述

一切正常!

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值