The directory structure of my C++ project is
/..
makefile <- the makefile is in root
/include <- subdirectory that has to be included while compiling
/obj <- target place for all *.o and final executable
/src <- sources
And my current makefile is:
CC=g++
CFLAGS=-c -Wall -std=c++11
INC=-Iinclude
SRC=src
TGT=obj
all: myapp
myapp: myapp.o
$(CC) $(TGT)/myapp.o -o $(TGT)/myapp
myapp.o:
$(CC) $(CFLAGS) $(INC) $(SRC)/myapp.cpp -o $(TGT)/myapp.o
clean:
rm -rf $(TGT)
mkdir $(TGT)
This worked for my first file. I am a total makefile novice – please help me compile all files under the /src directory and link them to an executable in /obj directory.
the makefile has to work under Windows, I am using MinGW and MSYS
Add a list of your source files:
and a list of corresponding object files:
and the target executable:
The rule for building the objects:
Now you must specify are the options for g++:
And everything together:
It is important, that in front of
$(CXX) ...there must be a “tab” character, not spaces.