makefile dependencies issue

I'm having trouble with my hand-made makefile. There is 1 file that is not being created (the last one)
It seems to be something about the dependencies of the files (maybe how I'm declaring them)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
objdir = obj 
headerdir = header

obj_1 = c.o f.o b.o a.o 
obj_2 = d.o 
obj_3 = e.o 

object_1 = $(addprefix $(objdir)/,$(obj_1))
object_2 = $(addprefix $(objdir)/,$(obj_2))
object_3 = $(addprefix $(objdir)/,$(obj_3))

objects = $(object_1) $(object_2) $(object_3)

foo: $(objects)

$(objdir)/%.o : src/%.cpp
    $(CXX) $< -c -I$(headerdir) -o $@


$(objdir)/a.o: $(addprefix $(headerdir)/,a.h b.h c.h d.h)
$(objdir)/b.o: $(addprefix $(headerdir)/,e.h c.h b.h a.h d.h)
$(objdir)/c.o: $(addprefix $(headerdir)/,e.h c.h b.h a.h d.h)
$(objdir)/d.o: $(addprefix $(headerdir)/,d.h b.h)
#$(objdir)/e.o: 
$(objdir)/f.o: $(addprefix $(headerdir)/,a.h b.h d.h)
g++ src/c.cpp -c -Iheader -o obj/c.o
g++ src/b.cpp -c -Iheader -o obj/b.o
g++ src/a.cpp -c -Iheader -o obj/a.o
g++ src/d.cpp -c -Iheader -o obj/d.o
g++ src/e.cpp -c -Iheader -o obj/e.o
So there are 6 sources but only 5 are compiled (always the last one declared)
There are three directories $ mkdir header obj src
All the files are empty $ touch header/{a..e}.h src/{a..f}.cpp

By the way, I used tabs, just don't know how to copy them
Last edited on
When I run your makefile I get:
 
    make: *** No rule to make target `src/%.cpp', needed by `obj'.  Stop.
Dunno about your error. Aparently the pattern expansion is not working

Some lines weren't empty but had tabs characters. There were spaces at the end of some lines, too.
After remove that, it seems to work. ¿Is this thing so sensitive?
make is quite sensitive, yes.
Topic archived. No new replies allowed.