c++ - Make and Re-Compiling Headers with Sub-Directories -
there few different questions related i'm trying do, such this, this, , this. however, i've looked @ there , link , i'm still not able work.
i have following make file (i had here). builds .os in build directory .cpps in source directory. want adjust if headers updated, re-compiles don't have make clean
whole thing (most particularly ones inc_dir1
folder).
cc = g++ cflags = -g -wall inc_dir1 = include inc_dir2 = c:/cppfiles/cpp_extra_libraries/armadillo-4.200.0/include inc_dir = $(inc_dir1) $(inc_dir2) includes = $(foreach d, $(inc_dir), -i$d) build_dir = build src_dir = test src = $(wildcard */*.cpp) vpath = $(src_dir) objs = $(addprefix $(build_dir)/, $(notdir $(src:.cpp=.o))) main = armadillo_extra_functions_test .phony: depend clean all: $(build_dir) $(main) @echo compilation complete $(build_dir): mkdir -p $@ $(build_dir)/%.o: %.cpp $(cc) $(cflags) $(includes) -c $< -o $@ $(main): $(objs) $(cc) $(cflags) $(includes) -o $(main) $(objs) clean: $(rm) *.o *~ $(main) $(build_dir)/*.o depend: $(src) makedepend $(includes) $^
the latest thing tried remove depend
, makedepend
statements , replace $(build_dir/%.o: %.cpp
statement with
deps = $(patsubst %.o, %.d, $(objs)) -include $(deps) $(build_dir)/%.o: %.cpp $(cc) -c $(cflags) $(includes) $< -o $@ $(cc) -c $(cflags) -mmd $< > $(deps)
without last line of these adjustments, make file runs, though not update headers. however, when add in last line error $(build_dir)/%.d
files not being there.
you right -mmd
flag, there no need complicate things:
inc_dir1 := include inc_dir2 := c:/cppfiles/cpp_extra_libraries/armadillo-4.200.0/include inc_dirs := $(inc_dir1) $(inc_dir2) build_dir := build src_dir := test srcs := $(wildcard $(src_dir)/*.cpp) objs := $(srcs:$(src_dir)/%.cpp=$(build_dir)/%.o) deps := $(objs:.o=.d) ldlibs := # -l flags ldflags := # -l flags cppflags := -mmd -mp $(foreach dir, $(inc_dirs), -i $(dir)) cxxflags := -w -wall main := armadillo_extra_functions_test .phony: clean all: $(main) @echo "compilation complete" $(main): $(objs) $(cxx) $(ldflags) $^ $(ldlibs) -o $@ clean: $(rm) -r $(main) $(build_dir) -include $(deps) $(build_dir): mkdir $@ $(build_dir)/%.o: $(src_dir)/%.cpp | $(build_dir) $(cxx) $(cppflags) $(cxxflags) -o $@ -c $<
some quick notes :
you're using c++. drop
$(cc)
,$(cflags)
c variables c++ versions:$(cxx)
,$(cxxflags)
variables.$(cppflags)
meant preprocessor flags, such-mmd
,-mp
or-i
.you need include rules gcc created in dependency files.
Comments
Post a Comment