how to create a makefile with bin src and inc subdirectories?

Hi everyone,

I'm just learning to use makefiles, i read a few tutorials but i have no idea of how to create a makefile with cpp files and the binary file in different direcories.

These are my directories:

Project/
|
|-makefile
|
|__src/__.cpp files
|
|
|__bin/__ .exe
|
|
|__inc/__ .h files
|
|
|__obj/__ .o files

I have done this:

CC = g++

CFLAGS   = -I.

SRCDIR = src
OBJDIR = obj
BINDIR = bin
INCDIR = inc

SOURCES  := $(wildcard $(SRCDIR)/*.cpp)
INCLUDES := $(wildcard $(INCDIR)/*.h)
OBJECTS  := $(SOURCES:$(SRCDIR)/%.cpp=$(OBJDIR)/%.o)


$(BINDIR)/project: $(OBJECTS)
    $(CC) -o $@ $(CFLAGS) $(OBJECTS)

$(OBJECTS): $(OBJDIR)/%.o : $(SRCDIR)/%.cpp $(INCDIR)/%.h
    $(CC) $(CFLAGS) -c $< -o $@

but console says "no rule to make target main.cpp, needed by project"

any ideas?
Last edited on
- you need to use tabs, no spaces
- SOURCES says *.cp instead of *.cpp
- your rule for creating the *.o files, ask for a .cpp and a .h with the same name. That's plain wrong
i corrected the cpp files, but, what about the other two points? i don't get it. as i said, i'm new in the makefiles/ and i don't understand the .o files
Last edited on
Topic archived. No new replies allowed.