Remember that make knows how to run gcc and g++, so for example you don't have to tell it an explicit rule for building .o files or for linking your executable. You also don't need to tell it to use the -c flag (Make knows to do that already).
In your original example, suppose you want the final executable to be called Exercises and that Exercises depends on two other compilation units stored in main.o and functions.o. You want main.o to be built from main.cpp and you want functions.o to be built from functions.cpp and you want Exercises.exe (or Exercises on Linux) to be built by linking main.o and functions.o together, and compiling Exercises.cpp and linking that as well. You want to use g++ as your C++ compiler and you also want to use it in the linking stage.
You could specify the rules yourself to make this happen, but it turns out that these steps are already handled by implicit rules. Here is the Makefile you need:
Running make with that project will run these invocations (on Win32, don't add the .exe extension to Exercises. This is handled by Make already).Code:CXX=g++
CC=$(CXX)
CXXFLAGS=-g -std=c++11 -Wall
CPPFLAGS=-DUSE_FOO
LDFLAGS=
LDLIBS=
all: Exercises
Exercises: functions.o main.o
Notice that an example feature macro USE_FOO is defined for each invocation. Suppose you want to rebuild your executable but to use a different feature which is activated by defining the macro USE_BAR instead. You don't have to edit the Makefile, just issue Make like this:Code:g++ -g -std=c++11 -Wall -DUSE_FOO -c -o functions.o functions.cpp
g++ -g -std=c++11 -Wall -DUSE_FOO -c -o main.o main.cpp
g++ -g -std=c++11 -Wall -DUSE_FOO Exercises.cpp functions.o main.o -o Exercises
-B is similar to choosing "Rebuild" from your IDE. I tend to use this all the time when building small projects with Makefile's to make sure everything gets built properly.Code:make -B CPPFLAGS=-DUSE_BAR