Reputation: 2118
I am new to makefiles and want to save all my object files in an own directory. I googled a lot and came to that solution:
CXX = clang++
# compiler flags
CXXFLAGS = -O3 -Wall -Werror -std=c++11
CFLAGS_SFML = -lsfml-graphics -lsfml-window -lsfml-system
SRCS = getInput.cpp createOutput.cpp main.cpp
OBJDIR = obj
OBJS = $(addprefix $(OBJDIR)/, SRCS:.cpp=.o)
all: program.exe
program.exe: $(OBJS)
$(CXX) $(CXXFLAGS) -o program.exe $(OBJS) $(CFLAGS_SFML)
$(OBJDIR)/%.o: %.cpp
$(CXX) $(CXXFLAGS) -c $< -o $@
When I try to run the makefile I get this error:
makefile:12: *** target pattern contains no `%'. Stop.
It seems as this error is quite common and does not tell the detail about what is wrong. It would be great if someone could help me.
Upvotes: 0
Views: 78
Reputation: 755
Problem with OBJS = $(addprefix $(OBJDIR)/, SRCS:.cpp=.o)
Try this one. First you have to make the obj directory also.
CXX = clang++
# compiler flags
CXXFLAGS = -O3 -Wall -Werror -std=c++11
CFLAGS_SFML = -lsfml-graphics -lsfml-window -lsfml-system
SRCS = main.cpp
OBJDIR = obj
OBJS = $(addprefix $(OBJDIR)/, $(SRCS:.cpp=.o))
all: program.exe
program.exe: $(OBJS)
$(CXX) $(CXXFLAGS) -o program.exe $(OBJS) $(CFLAGS_SFML)
$(OBJDIR)/%.o: %.cpp
$(CXX) $(CXXFLAGS) -c $< -o $@
For more information use this.
Upvotes: 1