I have the following project directory structure:
drwxr-xr-x+ 1 account Domain Users 0 Aug 20 16:16 ./
drwxr-xr-x+ 1 account Domain Users 0 Aug 20 08:48 ../
drwxr-xr-x+ 1 account Domain Users 0 Aug 20 10:55 include/
-rw-r--r-- 1 account Domain Users 597 Aug 20 16:16 Makefile
drwxr-xr-x+ 1 account Domain Users 0 Aug 20 10:55 obj/
drwxr-xr-x+ 1 account Domain Users 0 Aug 20 10:55 src/
in the src folder: main.cpp foo.cpp bar.cpp
in the include folder: foo.h bar.h
When I run the following Makefile, the object files are created in the project directory, not the obj
directory as I might expect from my Makefile:
1 ODIR = obj
2 SDIR = src
3 IDIR = include
4
5 _OBJS = main.o foo.o bar.o
6 OBJS = $(patsubst %,$(ODIR)/%,$(_OBJS))
7
8 CC = g++
9
10 CFLAGS = -w
11
12 PROG = program
13
14 #VPATH = src:include:obj:../src:../include:../obj
15
16 all: $(OBJS)
17 $(CC) $(CFLAGS) -I$(IDIR) $(OBJS) -o $(PROG)
18
19 $(ODIR)/main.o: $(SDIR)/main.cpp $(IDIR)/foo.h $(IDIR)/bar.h
20 $(CC) $(CFLAGS) -I$(IDIR) -c $(SDIR)/main.cpp
21
22 $(ODIR)/foo.o: $(SDIR)/foo.cpp $(IDIR)/foo.h
23 $(CC) $(CFLAGS) -I$(IDIR) -c $(SDIR)/foo.cpp
24
25 $(ODIR)/bar.o: $(SDIR)/bar.cpp $(IDIR)/bar.h
26 $(CC) $(CFLAGS) -I$(IDIR) -c $(SDIR)/bar.cpp
27
28 clean:
29 rm -f $(PROG) $(OBJS)
Can anybody clue me in on why this is happening? My linker doesn't see the object files because it thinks the files are in the obj directory.