I have four cpp files and so many .h files. I expect my make file generates the appropriate .d file for each .cpp file and compiles them to .o and then links them. Could some one tell me what is wrong with this code? it does not work in the way that it should.
Btw, I am beginner in makefile! Please do not link to somewhere with hard explanation for highly experts.
$make
g++ -c -g -Wall -Wconversion -Wfatal-errors -Wextra -std=c++11 -MD -MP -MF ./bin/obj/app/sim_rhs.d -o bin/obj/app/sim_rhs.o app/sim_rhs.cpp
app/sim_rhs.cpp:49:1: fatal error: opening dependency file ./bin/obj/app/sim_rhs.d: No such file or directory
}
^
compilation terminated.
make: *** [bin/obj/app/sim_rhs.o] Error 1
Cpp Files:
main.cpp
app/sim_rhs.cpp
app/sim_mids.cpp
app/sim_outputs.cpp
Makefile
SOURCES := main.cpp app/sim_rhs.cpp app/sim_mids.cpp app/sim_outputs.cpp
OUTDIR:= ./out
BINDIR:= ./bin
OBJDIR:= ./bin/obj
OBJECTS := $(addprefix $(OBJDIR)/,$(SOURCES:.cpp=.o))
DEPFILES:= $(OBJECTS:.o=.d)
CXX := g++
CXXFLAGS := -c -g -Wall -Wconversion -Wfatal-errors -Wextra -std=c++11 -MD -MP
LIBS:= -lboost_filesystem -lboost_system
# default
%:: $(BINDIR)/sim
# Link the executable
$(BINDIR)/sim: $(OBJECTS)
$(CXX) $(LDFLAGS) $^ -o $@ $(LIBS)
run:
$(BINDIR)/sim
$(OBJDIR)/%.o: %.cpp
$(CXX) $(CXXFLAGS) -MF $(OBJDIR)/$*.d -o $@ $<
-include $(DEPFILES)
Please avoid duplicate suggestion as I have an existing code. I do not want any other person's makefile template.
-
1I believe this question is duplicated: stackoverflow.com/questions/9582936/makefile-depency-issueRon Thompson– Ron Thompson2015年03月24日 04:06:58 +00:00Commented Mar 24, 2015 at 4:06
-
@RonThompson, I have an existing code. Could you tell me which part of it is wrong?ar2015– ar20152015年03月24日 04:08:18 +00:00Commented Mar 24, 2015 at 4:08
-
I don't think any part of it is wrong. I just think the makefile may need to be edited, like in the answer to that question. It looks like his solution was to create the necessary directory in the makefile.Ron Thompson– Ron Thompson2015年03月24日 04:09:55 +00:00Commented Mar 24, 2015 at 4:09
-
@RonThompson all output directories are fine. it is not the case.ar2015– ar20152015年03月24日 04:13:58 +00:00Commented Mar 24, 2015 at 4:13
-
You're right, sorry I overlooked that line in your file. I'm looking at it now.Ron Thompson– Ron Thompson2015年03月24日 04:14:50 +00:00Commented Mar 24, 2015 at 4:14