Reputation: 59
I'm writing the most basic makefile I can think of, just compiling one main.cpp. I tried every suggestion I can find from reading similar questions but I still cannot pinpoint my issue. Common mistake is using spaces instead of tabs, I checked that too.
The whole project layout is as follows:
/bin
/build
/src
|-----main.cpp
/Makefile
The main.cpp just prints "hello world".
Here's what the Makefile contains:
CXX = g++
WARNINGS = -Wall
OBJ = -c
OUTPUT = -o
BIN = bin
BUILD = build
SOURCE = src
executable:${BUILD}/main.o
${CXX} ${WARNINGS} ${OUTPUT} ${BIN}/program ${BUILD}/main.o
#c++ -wall -o bin/program src/main.o
main.o: ${SOURCE}/main.cpp
${CXX} ${WARNINGS} ${OBJ} ${OUTPUT} ${BUILD}/main.o ${SOURCE}/main.cpp
As you can see, there are instructions to build main.o! If I don't use the makefile variables and plainly write the commands (the commented out line), it works.
There is no missing file. Here's proof that main.cpp exists
Upvotes: 1
Views: 93
Reputation: 1525
Your Fix: change main.o to ${BUILD}/main.o then make command can relate it
CXX = g++
WARNINGS = -Wall
OBJ = -c
OUTPUT = -o
BIN = bin
BUILD = build
SOURCE = src
executable:${BUILD}/main.o
${CXX} ${WARNINGS} ${OUTPUT} ${BIN}/program ${BUILD}/main.o
${BUILD}/main.o: ${SOURCE}/main.cpp #<------ watch this line
${CXX} ${WARNINGS} ${OBJ} ${OUTPUT} ${BUILD}/main.o ${SOURCE}/main.cpp
Upvotes: 1