如何修复“make (e=2): 系统找不到指定的文件。”

Roy*_*Dai 3 makefile mingw32

我想使用 mingW32_make.exe 在命令提示符下编译 C 代码。错误信息显示

rm -f obj/*.o
process_begin: CreateProcess(NULL, rm -f obj/*.o, ...) failed.
make (e=2): The system cannot find the file specified.
makefile:11: recipe for target 'all' failed
mingw32-make.exe: *** [all] Error 2
Run Code Online (Sandbox Code Playgroud)

makefile如下所示

CC=gcc
INC_DIR=../include
LIBS=-lregex
ODIR=obj
_OBJ=main.o BVPA.o BVPA-cube.o BVPA-cif.o BVPA-hk.o BVPA-path.o BVPA-math.o BVPA-cmd.o BVPA-gui.o BVPA-vesta.o MT19937AR.o
OBJ=$(patsubst %,$(ODIR)/%,$(_OBJ))
TARGET=../bin/BVPA_win.exe
CFLAGS=-I$(INC_DIR) -Wall -g

all: $(TARGET)
    rm -f $(ODIR)/*.o

$(TARGET): $(OBJ)
    $(CC) $(CFLAGS) -o $@ $^ $(LIBS)

$(ODIR)/%.o: %.c
    $(CC) $(CFLAGS) -c -o $@ $^

clean:
    rm -f $(ODIR)/*.o
Run Code Online (Sandbox Code Playgroud)

'''

小智 5

我遇到了同样的问题,这是解决方法。原因是从别人的评论中给出的:

Windows看不懂rm

当您运行 make clean 时,它将清除所有.o文件。

干净的:

del *.o
Run Code Online (Sandbox Code Playgroud)

  • 我怎么可以在 powershell 中调用 rm 但不能从 makefile 中调用? (3认同)