1

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 enter image description here

1 Answer 1

1

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 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.