Error: "Mixed implicit and static template rules" in my Makefile

I had a working one Makefilefor small C ++ applications that only had a few source code files inside one folder, which was also an output folder. Now I am trying to separate the source and object files and ran into a problem. This is what my make file looks like right now, I will tell you in detail where the problem arises below.

CC = gcc
CXX = g++
RM = del

TARGET = plox.exe

CFLAGS = -Wall -ggdb -O3 $(INCLUDE)
CXXFLAGS = -std=c++11 -Wall -ggdb -O3 $(INCLUDE)
LDFLAGS = $(LIB) -lglfw3 -lopengl32 -lglu32 -lgdi32

INCLUDE = -I$(GLFW_INC) -I$(GLAD_INC)
LIB = -L$(GLFW_LIB)

SRC_DIR = src
BUILD_DIR = build

GLFW_DIR = d:/external/glfw-3.1
GLFW_INC = $(GLFW)/include
GLFW_LIB = $(GLFW)/lib64

GLAD = d:/external/glad-c
GLAD_INC = $(GLAD)/include

CXX_SOURCES = $(SRC_DIR)/%.cpp
CXX_OBJS = $(addprefix $(BUILD_DIR)/, $(CXX_SOURCES:.cpp=.o))
OBJS = $(CXX_OBJS) $(BUILD_DIR)/glad.o

all: $(TARGET)

$(TARGET): $(OBJS)
    $(CXX) -o $@ $^ $(LDFLAGS)

$(CXX_OBJS): %.o: $(SRC_DIR)%.cpp
    $(CXX) $(CXXFLAGS) -c -o $@ $<

$(BUILD_DIR)/glad.o: src/glad.c
    $(CC) -c $(CFLAGS) -c -o $(BUILD_DIR)/glad.o $(SRC_DIR)/glad.c

.PHONY: clean

clean:
    $(RM) $(TARGET) $(OBJS)

The problem is in the line:

$(CXX_OBJS): %.o: $(SRC_DIR)/%.cpp

Before my changes, it looked like this:

$(CXX_OBJS): %.o: %.cpp

, , . , , , . , , , . , $(CXX_OBJS). , build/src/test.o build/test.o?

addprefix ? ; ? , $(SRC_DIR) , , , , , . ( CXX_OBJS ), $(CXX_OBJS) %.o, .cpp, - build.

, , , !

+4
2

() . (%). :

CXX_SOURCES = $(SRC_DIR)/%.cpp
CXX_OBJS = $(addprefix $(BUILD_DIR)/, $(CXX_SOURCES:.cpp=.o))
$(CXX_OBJS): %.o: $(SRC_DIR)%.cpp

CXX_OBJS $(BUILD_DIR)/$(SRC_DIR)/%.o, , .

, CXX_SOURCES. , :

CXX_SOURCES := $(wildcard $(SRC_DIR)/*.cpp)

+3

@MadScientist ( , % <wildcard)), Makefile : mingw32-make -lglfw3, $(GLFW) GLFW_INC GLFW_LIB, . $(GLFW_DIR).

0

All Articles