I know this has been asked a lot, I've looked at a couple of responses but can't figure out what's wrong. I'm trying to store all my object files in a build directory. In the root folder I have my Makefile, and the following directories: include, bin, build, src, and rsrc. I want the object files stored in the build directory, and executables stored in bin. Here is my Makefile.
CFLAGS = -Wall -Werror
DIRS = -I $(IDIR) -I $(SRCDIR) -I $(ODIR)
IDIR = include
SRCDIR = src
ODIR = build
DEPS = include/map_reduce.h include/const.h
BINS = mapreduce
all: $(BINS)
_OBJ = map_reduce.o main.o
OBJ = $(patsubst %, $(ODIR)/%,$(_OBJ))
$(ODIR)/%.o: %.c $(DEPS)
gcc -c -o $@ $< $(CFLAGS)
mapreduce: $(OBJ)
gcc $(CFLAGS) $(DIRS) $^ -o $@
clean:
rm -f *.o $(BINS)
I currently don't have a rule for storing executables in the bin folder, but I figure if I can understand how to store the object files in build then that part should not be difficult.
I'm getting the error "No rule to make target build/map_reduce.o needed by mapreduce"
Any insight to help me understand what's going on here would be greatly appreciated!
make
are you using? – user58697:=
not=
. Third, variable names (including macro names) that begin with_
followed by a capital letter and begin with__
are reserved for the system, The user should not be polluting the system name space with names like_OBJ
– user3629249$(ODIR)/%.o: %.c $(DEPS)
) or he has to make the dependencies not templated in a different rule. – Luis Colorado