Makefile 错误 - 找不到文件 - *.cpp

Makefile error - File not found - *.cpp

所以,我尝试在用 c++ 制作的个人 GameEngine 中编译游戏。我使用 makefile 来编译所有文件。在 Linux 上编译很好,但在 Windows 上,使用 MinGW,我得到这些错误:

C:\Users\Utilisateur\Desktop\Code\GitProjects\HyperGameEngine>make
sh.exe
process_begin: CreateProcess(NULL, uname -s, ...) failed.
File not found - *.cpp
File not found - -TYPE
File not found - D
process_begin: CreateProcess(NULL, uname -s, ...) failed.
process_begin: CreateProcess(NULL, uname -s, ...) failed.
g++  -o "/build"/a.exe  -I"./inc/lua/" -I"inc" -I"./inc/" -I"./inc/SDL2/" -
L"lib/Windows" -static -static-libstdc++ -static-libgcc -std=c++14 -std=gnu++14 
-Wunused-parameter -Wstrict-aliasing -lSDL2main -lSDL2 -lSDL2_net -mwindows -
lglew32s -llibSOIL -lopenal32 -lopengl32 -lBox2D -lfreetype -llua53 -dl
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../../mingw32/bin/ld.exe: cannot 
open output file /build/a.exe: No such file or directory
collect2.exe: error: ld returned 1 exit status
make: *** ["/build"/a.exe] Erreur 1

这里是 makefile :

#TODO Authoritive Server, Basic Server Browser (Hearthbeat to web server)? (maybe steam support)?
#
LOCAL_ALLOW_UNDEFINED_SYMBOLS := true

$(info $(SHELL))
ifeq ($(shell uname -s), Linux)
TARGET_EXEC ?= a.out
endif
ifeq ($(OS),Windows_NT)
TARGET_EXEC ?= a.exe
endif

BUILD_DIR ?= "$(CURRENT_DIRECTORY)/build"
SRC_DIRS ?= "$(CURRENT_DIRECTORY)/src" # src or Server

#QMAKE_CXXFLAGS += -std=c++11

SRCS := $(shell find $(SRC_DIRS) -name *.cpp -or -name *.c -or -name *.s)
OBJS := $(SRCS:%=$(BUILD_DIR)/%.o)
DEPS := $(OBJS:.o=.d)

INC_DIRS := $(shell find $(SRC_DIRS) -type d)
INC_FLAGS := $(addprefix -I,$(INC_DIRS))

ifeq ($(shell uname -s), Linux)
CPPFLAGS ?= $(INC_FLAGS) -std=c++14 -MMD -MP -g -Wall -Wextra -O3 -fpermissive #-Werror
endif
ifeq ($(OS),Windows_NT)
CPPFLAGS ?= $(INC_FLAGS) -lmingw32 -std=c++14 -MMD -MP -g -Wall -Wextra -O3 -fpermissive -mwindows #-Werror
endif

 #LINKER_FLAGS specifies the libraries we're linking against -L/usr/lib/nvidia-375/ -I./inc/ -w -lGLEW -lGL -lSLD2
ifeq ($(shell uname -s), Linux)
LINKER_FLAGS = -I./inc/ -I./inc/lua/ -L./lib/Linux/ -lSDL2 -lGLEW -lGL -lSOIL -lopenal -lBox2D -lSDL_net -llua53 -lfreetype -ldl
endif
ifeq ($(OS),Windows_NT)
LINKER_FLAGS = -dl # -I"./inc/lua/" -I"inc" -I"./inc/" -I"./inc/SDL2/" -L"lib/Windows" -static -static-libstdc++ -static-libgcc -std=c++14 -std=gnu++14 -Wunused-parameter -Wstrict-aliasing -lSDL2main -lSDL2 -lSDL2_net -mwindows -lglew32s -llibSOIL -lopenal32 -lopengl32 -lBox2D -lfreetype -llua53 -dl #-I"./inc/steam/" -lsteam_api #-llua53 -dl
endif

$(BUILD_DIR)/$(TARGET_EXEC): $(OBJS)
    g++ $(OBJS) -o $@ $(LDFLAGS) $(LINKER_FLAGS)

# assembly
$(BUILD_DIR)/%.s.o: %.s
    $(MKDIR_P) $(dir $@)
    $(AS) $(ASFLAGS) $(LINKER_FLAGS) -c $< -o $@

# c source
$(BUILD_DIR)/%.c.o: %.c
    $(MKDIR_P) $(dir $@)
    g++ -std=c++0x $(CPPFLAGS) $(CFLAGS) $(LINKER_FLAGS) -c $< -o $@

# c++ source
$(BUILD_DIR)/%.cpp.o: %.cpp
    $(MKDIR_P) $(dir $@)
    g++ $(CPPFLAGS) $(CXXFLAGS) $(LINKER_FLAGS) -c $< -o $@


.PHONY: clean

clean:
    $(RM) -r $(BUILD_DIR)/$(SRC_DIRS)

-include $(DEPS)

MKDIR_P ?= mkdir -p

然后,所有库都在 Linux 上运行,我尝试重新安装 MinGW,但没有任何变化。 makefile 中的一些更改做了一些事情。更改 Windows 部分中 LinkerFlags 的顺序是使错误消息变小的原因。

也许问题不在 MinGW.. 据我了解,MinGW 是一组编译器。所以,gcc 和 g++。

MinGW includes:

A port of the GNU Compiler Collection (GCC), including C, C++, ADA
and Fortran compilers;

GNU Binutils for Windows (assembler, linker, archive manager);

A command-line installer, with optional GUI front-end, (mingw-get) for MinGW and MSYS deployment on MS-Windows;

A GUI first-time setup tool (mingw-get-setup), to get you up and running with mingw-get. http://www.mingw.org/

如果您能够 运行 在单个“hello world”文件上运行 g++ 并获得一个 exe,MinGW 应该可以正常工作。

所以,貌似大部分MinGW和gnuwin32都不是问题! 正如 user657267 指出的那样,您不能在 Windows 上使用 Linux 命令。 这就是说,这并不意味着它是不可能的,只是默认情况下不存在。 “使”这项工作的一种方法是安装 Git (https://git-scm.com/download/win) 您可以选择所有默认选项... 安装后,转到安装路径并将 bin 文件夹的路径传递到路径环境变量。 这是 screenshot of my Environment Variables