0

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.

asked Mar 24, 2015 at 4:00
11
  • 1
    I believe this question is duplicated: stackoverflow.com/questions/9582936/makefile-depency-issue Commented Mar 24, 2015 at 4:06
  • @RonThompson, I have an existing code. Could you tell me which part of it is wrong? Commented 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. Commented Mar 24, 2015 at 4:09
  • @RonThompson all output directories are fine. it is not the case. Commented Mar 24, 2015 at 4:13
  • You're right, sorry I overlooked that line in your file. I'm looking at it now. Commented Mar 24, 2015 at 4:14

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.