MrDuk
MrDuk

Reputation: 18242

Troubles with makefiles

I have 4 components:

My executables should be Bin1 and Bin2 - MainAand MainB use ImplA and ImplB, respectively. My makefile is:

CC=g++
CCOPTS=-g -w

OBJS = $(BINDIR)/MainA.o $(BINDIR)/MainB.o $(BINDIR)/ImplA.o $(BINDIR)/ImplB.o 
TARGETS = $(BINDIR)/Bin1 $(BINDIR)/Bin2
BINDIR = build

all: $(TARGETS) $(OBJS)

clean:
    rm -f $(TARGETS) $(OBJS)

.PHONY: all clean

$(BINDIR)/Bin1 : $(BINDIR)/MainA.o $(BINDIR)/ImplA.o
    $(CC) -o $@ $^ $(CFLAGS) $(LIBS)

$(BINDIR)/Bin2 : $(BINDIR)/MainB.o $(BINDIR)/ImplB.o
    $(CC) -o $@ $^ $(CFLAGS) $(LIBS)

$(BINDIR)/%.o: %.cpp
    $(CC) -c $(CCOPTS) -o $@ $<

When I attempt to make, I get:

g++ -c -g -w -o build/MainA.o MainA.cpp
Assembler messages:
Fatal error: can't create build/MainA.o: No such file or directory
make: *** [build/MainA.o] Error 1

What don't I understand?

Upvotes: 0

Views: 53

Answers (1)

MadScientist
MadScientist

Reputation: 100781

Probably the directory build doesn't exist.

Upvotes: 1

Related Questions