Add a list of source files:
SOURCES = $(wildcard $(SRC)/*.cpp)
and a list of related object files:
OBJS = $(addprefix $(TGT)/, $(notdir $(SOURCES:.cpp=.o)))
and target executable:
$(TGT)/myapp: $(OBJS) $(CXX) $(LDFLAGS) $(OBJS) -o $@
The rule for building objects:
$(TGT)/%.o: $(SRC)/%.cpp $(CXX) $(CXXFLAGS) -c $< -o $@
Now you must specify the g ++ options:
INCLUDES = -Iinclude CXXFLAGS = -Wall -std=c++11 $(INCLUDES)
And all together:
SRC=src TGT=obj INCLUDES = -Iinclude CXXFLAGS = -Wall -std=c++11 $(INCLUDES) SOURCES = $(wildcard $(SRC)/*.cpp) OBJS = $(addprefix $(TGT)/, $(notdir $(SOURCES:.cpp=.o))) $(TGT)/%.o: $(SRC)/%.cpp $(CXX) $(CXXFLAGS) -c $< -o $@ $(TGT)/myapp: $(OBJS) $(CXX) $(LDFLAGS) $(OBJS) -o $@
It is important that before the $(CXX) ... should be a "tab" character, not spaces.
Olaf dietsche
source share