添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

i want to use mingW32_make.exe to compile a C code on command prompt. The error message shows

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

The makefile is show below

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
                I'm guessing your shell does not support rm...   Try doing $(info SHELL is $SHELL) to figure out which shell you're configured for...
– HardcoreHenry
                Mar 26, 2019 at 15:18
                As @HardcoreHenry correctly points out, cmd.exe does not understand rm. You'll either need to run it under something like MSYS or replace rm -f with del /f, but you'll also then need to replace the slashes of the files you're deleting with backslashes, because del doesn't understand forward slashes.
– user657267
                Mar 26, 2019 at 21:01
                @user657267 Thanks for the advice. How to run it under msys? I have add the pacake in MingW.
– Roy Dai
                Mar 27, 2019 at 3:16
                Oops, getting my bash and make mixed up:  $(info SHELL is ${SHELL})   (makefiles require you add braces to multi-character variables)
– HardcoreHenry
                Mar 27, 2019 at 14:53

I have encountered the same question and here is the fix. The reason is given from other's comments:

Windows does not understand rm.

When you run make clean, it will clear out all .o files.

clean:

del *.o
                @YosefAhab As far as I have understood, the Makefile spawns new shells to execute the tasks and this shell might not be the shell that you started the Makefile with, i.e. Powershell. I found this [stackoverflow.com/questions/61754413/… solution by Aaron N. Brock to set the Powershell as the executing shell and it worked for me.
– JustABit
                Jan 27 at 15:25
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.