admin管理员组文章数量:1333439
I am trying to compile both C and C++ files into a DLL using a makefile but whenever I build I get the error MINGW32-MAKE: *** No rule to make target 'vendor\whatever*.cpp.o', needed by 'module.dll'. Stop.
All the files in the main source folder compile properly.
Im pretty sure the issue is with how I get all the .o files with patsubst and subst but I am unsure on how to fix it.
I know this is dumb but I have never used makefiles before.
.PHONY: build clean mkdir run print
CC := gcc.exe
CXX := g++.exe
CWD := $(subst \,/,$(shell cd))
SRCDIR := $(CWD)/src
INCDIR := $(CWD)/inc
BINDIR := $(CWD)/build
SRC_C := $(shell dir /a:-d /b/s $(shell cd)\src\\*.c)
SRC_C := $(subst \,/,$(SRC_C))
CCFLAGS := -O2 -I "$(CWD)/vendor" -I "$(CWD)/inc"
LDLIBS := -lws2_32 -lkernel32 -luser32 -ldwmapi -ld3d11 -ldxgi -ldxguid -lgid32 -ld3dcompiler
LDFLAGS := -s -shared -mconsole -static-libgcc -static-libstdc++
EXE := module.dll
OBJECTS := $(SRC_C)
OBJECTS := $(subst \,/,$(OBJECTS))
OBJECTS := $(subst /src,,$(patsubst $(CWD)/%.c,$(BINDIR)/int/%.c.o,$(OBJECTS)))
build: $(EXE)
$(EXE): $(OBJECTS)
$(CC) $(LDFLAGS) $(OBJECTS) -o $@ $(LDLIBS)
$(CWD)/int/%.c.o: $(SRC_C)/%.c
$(shell echo $<)
$(CC) -c -std=c99 $(CCFLAGS) -o $< $@
Edit: Simplified the makefile with the same issue
I am trying to compile both C and C++ files into a DLL using a makefile but whenever I build I get the error MINGW32-MAKE: *** No rule to make target 'vendor\whatever*.cpp.o', needed by 'module.dll'. Stop.
All the files in the main source folder compile properly.
Im pretty sure the issue is with how I get all the .o files with patsubst and subst but I am unsure on how to fix it.
I know this is dumb but I have never used makefiles before.
.PHONY: build clean mkdir run print
CC := gcc.exe
CXX := g++.exe
CWD := $(subst \,/,$(shell cd))
SRCDIR := $(CWD)/src
INCDIR := $(CWD)/inc
BINDIR := $(CWD)/build
SRC_C := $(shell dir /a:-d /b/s $(shell cd)\src\\*.c)
SRC_C := $(subst \,/,$(SRC_C))
CCFLAGS := -O2 -I "$(CWD)/vendor" -I "$(CWD)/inc"
LDLIBS := -lws2_32 -lkernel32 -luser32 -ldwmapi -ld3d11 -ldxgi -ldxguid -lgid32 -ld3dcompiler
LDFLAGS := -s -shared -mconsole -static-libgcc -static-libstdc++
EXE := module.dll
OBJECTS := $(SRC_C)
OBJECTS := $(subst \,/,$(OBJECTS))
OBJECTS := $(subst /src,,$(patsubst $(CWD)/%.c,$(BINDIR)/int/%.c.o,$(OBJECTS)))
build: $(EXE)
$(EXE): $(OBJECTS)
$(CC) $(LDFLAGS) $(OBJECTS) -o $@ $(LDLIBS)
$(CWD)/int/%.c.o: $(SRC_C)/%.c
$(shell echo $<)
$(CC) -c -std=c99 $(CCFLAGS) -o $< $@
Edit: Simplified the makefile with the same issue
Share Improve this question edited Nov 21, 2024 at 20:22 FenrirBots asked Nov 21, 2024 at 6:28 FenrirBotsFenrirBots 218 bronze badges 12 | Show 7 more comments1 Answer
Reset to default 0So I fixed it myself after a few hours of testing stuff.
I took a template makefile and modified it to suit what I need
.DEFAULT_GOAL = build
CC = gcc
CXX = g++
LD = g++
CCFLAGS = -O2 -I"vendor" -I"inc"
LDFLAGS = -s -shared -mconsole -static-libgcc -static-libstdc++
LDLIBS =
ifeq ($(RENDERER),d3d11)
CCFLAGS := $(CCFLAGS) -DRENDERER_USE_DIRECTX11
LDLIBS := $(LDLIBS) -ld3d11 -ldxgi -ldxguid -ld3dcompiler
endif
ifeq ($(RENDERER),d3d12)
CCFLAGS = $(CCFLAGS) -DRENDERER_USE_DIRECTX12
endif
ifeq ($(RENDERER),glfw)
CCFLAGS := $(CCFLAGS) -DRENDERER_USE_GLFW
endif
SRCDIR = src
SRC_FILES := $(subst \,/, $(shell dir /a:-d /b/s $(shell cd)\src\\*.c)) $(subst \,/, $(shell dir /a:-d /b/s $(shell cd)\src\\*))
ifeq ($(BACKEND),imgui)
SRC_FILES := $(SRC_FILES) $(subst \,/, $(shell dir /a:-d /b/s vendor\imgui\src\*.cpp))
CCFLAGS := $(CCFLAGS) -DRENDERER_USE_IMGUI
LDLIBS := $(LDLIBS) -lgdi32 -luser32 -ldwmapi
endif
ifeq ($(BACKEND),nuklear)
SRC_FILES := $(SRC_FILES) $(subst \,/, $(shell dir /a:-d /b/s vendor\nuklear\src\*.c))
CCFLAGS += -DRENDERER_USE_NUKLEAR
endif
SRC_FILES := $(subst $(subst \,/,$(shell cd))/,, $(SRC_FILES))
INTDIR = build/int
INT_FILES := $(SRC_FILES)
INT_FILES := $(patsubst %, $(INTDIR)/%.o, $(INT_FILES))
INT_FILES := $(patsubst %.c, $(INTDIR)/%.o, $(INT_FILES))
INT_FILES := $(patsubst %.cpp, $(INTDIR)/%.o, $(INT_FILES))
INT_FILES := $(subst src/,, $(INT_FILES))
OUTDIR = build/bin
OUT_FILE = module.dll
.PHONY: test
test:
@echo $(SRC_FILES)
@echo $(INT_FILES)
.PHONY: clean
clean:
$(RM) $(INT_FILES)
$(RM) $(OUTDIR)/$(EXE)
.PHONY: build
build: $(OUTDIR)/$(OUT_FILE)
$(OUTDIR)/$(OUT_FILE): $(INT_FILES)
$(LD) $(LDFLAGS) $(INT_FILES) -o $@ $(LDLIBS)
$(INTDIR)/%.o: $(SRCDIR)/%.c
$(CC) $(CCFLAGS) -c -o $@ $<
$(INTDIR)/%.o: $(SRCDIR)/%
$(CXX) $(CCFLAGS) -c -o $@ $<
$(INTDIR)/%.o: $(SRCDIR)/%.cpp
$(CXX) $(CCFLAGS) -c -o $@ $<
$(INTDIR)/vendor/nuklear/%.o: vendor/nuklear/src/%.cpp
$(CC) $(CCFLAGS) -c -o $@ $<
$(INTDIR)/vendor/imgui/%.o: vendor/imgui/src/%.cpp
$(CXX) $(CCFLAGS) -c -o $@ $<
-include $(DEPENDS)
I know its probably bad code but it works so :p
本文标签:
版权声明:本文标题:windows - MINGW32-MAKE: *** No rule to make target '*.cpp.o', needed by 'module.dll'. Stop - Sta 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742309514a2450585.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
/
) in your makefiles for directory separators, never backslashes (\). Almost all Windows facilities support forward slashes as well. The only ones that don't are cmd builtin commands, likermdir
etc. – MadScientist Commented Nov 21, 2024 at 12:53OBJECTS
variable is empty. You can add$(info OBJECTS is '$(OBJECTS)')
to the makefile after you've set it, and it will print the value. You can use$(info ...)
to print the value of other variables. If the variable is empty, then$(EXE): $(OBJECTS)
expands to justmodule.dll:
and there are no prerequisites listed, so make doesn't build them. – MadScientist Commented Nov 21, 2024 at 20:10sh
as the shell rather thancmd
(which should happen automatically as long as it's in PATH, which should happen automatically if you installed Make from MSYS2). – HolyBlackCat Commented Nov 21, 2024 at 20:23