基本上我正在嘗試使用 OpenGL 和 SDL 構建游戲引擎。我使用 makefile 來編譯它,但我得到一個錯誤。在我重新組織我的檔案夾結構并將 src 檔案夾包含到包含路徑后,錯誤開始出現,因此我可以使用絕對路徑訪問它們。例如Renderer/Camera.h,而不是../Renderer/Camera.h.
當我嘗試編譯我的專案時,出現此錯誤:
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find src: Permission denied
collect2.exe: error: ld returned 1 exit status
mingw32-make: *** [Makefile:57: build] Error 1
這是我的makefile
RELEASE_MACRO:=-D RELEASE
DEBUG_MACRO:=-D DEBUG
OS_MACRO:=-D
BIN := bin
SRC := src
INCLUDE := -Isrc -Iinclude
LIB := lib
#Check the OS
ifeq ($(OS),Windows_NT)
# the compiler: gcc for C program, define as g for C
CC := g
# The windows command for delete
DEL := del
# The windows slash for directory
SLASH := \
# Indicating that we dont need wine, unlike in linux
WINE :=
OS_MACRO =__WINDOWS__
SOURCES := $(wildcard $(SRC)/***/*.cpp) $(wildcard $(INCLUDE)/***/*.cpp) $(wildcard $(SRC))
else
# CURRENTLY NOT WORKING
# Linux compiler for windows executables (64 bits)
CC := x86_64-w64-mingw32-g
# Linux command for delete (rm -f)
DEL := $(RM)
# Linux slash for directory
SLASH := '/'
# Wine, program for executing windows apps .exe
WINE := wine
OS_MACRO =__LINUX__
SOURCES := $(shell dir . -r *.cpp)
endif
# compiler flags:
# -g adds debugging information to the executable file
# -Wall turns on most, but not all, compiler warnings
CFLAGS:= -g -Wall
# libraries to link to the project
LIBRARIES := -lmingw32 -lSDL2main -lSDL2 -lSDL2_net -lSDL2_mixer -lmingw32 -lopengl32 -lglew32 -lglu32 -lSDL2main -lSDL2 -lSDL2_image
# the build target executable
EXECUTABLE := game
all: build
showfiles:
@echo $(SOURCES)
# Builds the executable game
build:
echo "Building..."
$(CC) $(CFLAGS) $(INCLUDE) -L $(LIB) $(OS_MACRO) $(DEBUG_MACRO) -o $(BIN)/$(EXECUTABLE) $(SOURCES) $(LIBRARIES)
# Run the game
run:
@echo "Executing..."
$(WINE) $(BIN)/$(EXECUTABLE)
# Build then run the game
build-and-run: clean build run
# Remove the executable
clean:
@echo "Clearing..."
$(DEL) bin$(SLASH)$(EXECUTABLE).exe
這是我的專案檔案夾結構

uj5u.com熱心網友回復:
這是無效的:
SOURCES := $(wildcard $(SRC)/***/*.cpp) $(wildcard $(INCLUDE)/***/*.cpp) $(wildcard $(SRC))
我不知道你從哪里得到通配符語法,但它并沒有按照你的想法做。 ***與*GNU make 使用的標準 glob 語法相同。您是否真的希望.cpp在您的目錄中找到檔案$(INCLUDE)?那會很奇怪。
正如 ssbssa 所指出的那樣,問題在于$(wildcard $(SRC))它將擴展到$(wildcard src)is just src,因此您試圖將一個目錄添加到您的鏈接行,這是非法的并且聯結器會抱怨。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/513861.html
標籤:C 生成文件汇编明威
