You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Makefile执行make clean报错,make命令正常运行,请求排查原因

执行make clean时报错“process_begin: CreateProcess(NULL, ls, ...) failed”的原因

问题场景

你的Makefile内容:

CC=gcc

output.exe: main.o
    $(CC) main.o -o output.exe

main.o: main.cpp
    $(CC) -c main.cpp -o main.o

clean:
    rm *.o

执行make编译正常,但执行make clean时抛出错误:

rm *.o
process_begin: CreateProcess(NULL, ls, ...) failed.
make (e=2): The system cannot find the file specified.
make: *** [Makefile:10: clean] Error 2

错误原因

  1. 你当前是在Windows系统下运行GNU Make,Windows原生环境没有rm这类Unix/Linux系统的命令。
  2. make编译正常是因为gcc命令已通过MinGW/MSYS等工具加入了系统环境变量,但rm命令不在默认PATH中,导致Make无法找到该命令执行。错误信息里提到的ls是Make在尝试解析Unix风格命令时触发的额外调用,本质也是因为缺少Unix工具环境。

解决方法

  • 方法一:改用Windows原生命令
    将Makefile中的clean目标替换为Windows的del命令:
    clean:
        del *.o
    
  • 方法二:使用完整的Unix兼容环境
    打开MSYS/MinGW提供的终端窗口,在该环境下执行make clean,此时rm等Unix命令可以正常识别执行。

内容的提问来源于stack exchange,提问作者Jhon Margalit

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.17 20:32:06