产生错误:系统找不到指定的路径

时间:2020-04-20 15:21:39

标签: windows makefile mingw

运行mingw32-make命令时出现Make错误:

PS D:\> mingw32-make
cd src; mingw32-make
The system cannot find the path specified.
mingw32-make: *** [Makefile:4: all] Error 1

但是当我列出Makefile中列出的实际命令(即cd src; mingw32-make)时,构建就成功完成了。

PS D:\> cd src; mingw32-make
g++ -std=c++17 -Wall -Wextra -Wpedantic -Wformat -Wchkp -I../include -c account.cpp
g++ -std=c++17 -Wall -Wextra -Wpedantic -Wformat -Wchkp -I../include -c customer.cpp
g++ -std=c++17 -Wall -Wextra -Wpedantic -Wformat -Wchkp -I../include -c display.cpp
g++ -std=c++17 -Wall -Wextra -Wpedantic -Wformat -Wchkp -I../include -c main.cpp
g++ -std=c++17 -Wall -Wextra -Wpedantic -Wformat -Wchkp -I../include -c passbook.cpp
g++ -std=c++17 -Wall -Wextra -Wpedantic -Wformat -Wchkp -I../include -c security.cpp
g++ -std=c++17 -Wall -Wextra -Wpedantic -Wformat -Wchkp -I../include -c staff.cpp
g++ -o Bank account.o customer.o display.o main.o passbook.o security.o staff.o

但是,当我在Ubuntu上使用Make进行构建时,此问题不存在。

这是我的根目录中的Makefile:

DIR = src

all:
    cd $(DIR); mingw32-make

clean:
    cd $(DIR); mingw32-make clean

这是我src子目录中的Makefile:

# Compiler options
# -std=c++17 enables ISO C++ 17 standard

CC = g++
CCFLAGS = -std=c++17 -Wall -Wextra -Wpedantic - 
Wformat -Wchkp

i = ../include

# LOCFLAGS used to set tell the compiler where to find a
# header that is not in the same directory as the source 
file itself
# LOCFLAGS will be set in directory level makefiles as 
needed

LOCFLAGS = -I../include

# The list of object files that can be made in this 
subdirectory
# is assigned to the make macro named $OBJECTS

OBJECTS = account.o customer.o display.o main.o 
passbook.o \
      security.o staff.o

# This rule says that the target named "all" depends on 
those
# files. Executing "make all" in this subdirectory will cause
# make to build the object files (.o) listed in the macro 
$OBJECTS
# and create an executable named "Bank" by linking them

all: $(OBJECTS)
    $(CC) -o Bank $(OBJECTS)

# rule that says how to make a .o object file from a .cpp 
source file
# for a given source file in a given directory you could 
compile it
# into an object file by executing "make filename.o"

# $< and $@ are macros defined by make
#     $< refers to the file being processed (i.e., compiled or 
linked )
#     $@ refers to the generated file

%.o: %.cpp
    $(CC) $(CCFLAGS) $(LOCFLAGS) -c $<

# target to clean up the object files, core files and 
executables
# executing "make clean" in this subdirectory will remove 
all
# files named core, "Bank" or any file ending in .o or 
.stackdump

clean:
    del $(OBJECTS) core *.stackdump Bank

1 个答案:

答案 0 :(得分:0)

在Windows上,您运行在command.com外壳程序中,而不是POSIX外壳程序中。在command.com中,语法cd src; mingw32-make不合法。例如,如果我在Windows系统上打开command.com终端,则会看到:

C:\Users\build> cd src; echo hi
The system cannot find the path specified.

在Windows command.com中,命令分隔符是单个&而不是分号。

如果要便携式更改目录,可以对GNU make使用-C选项。另外,您应该始终使用$(MAKE)变量,而不要手工写出make命令:

all:
        $(MAKE) -C $(DIR)