title: Preprocessor macro definition via a Makefile does not work properly in c++
body: <p>For my c++ code I need a custom processor macro that will be defined during compilation. According to what I have read I concluded in the following Makefile:</p>
  
  <pre><code>CC := g++ 
  
  # Folders
  SRCDIR := src
  BUILDDIR := build
  TARGETDIR := bin
  
  # Targets
  EXECUTABLE := app
  TARGET := $(TARGETDIR)/$(EXECUTABLE)
  
  SRCEXT := cpp
  SOURCES := $(shell find $(SRCDIR) -type f -name *.$(SRCEXT))
  OBJECTS := $(patsubst $(SRCDIR)/%,$(BUILDDIR)/%,$(SOURCES:.$(SRCEXT)=.o))
  CFLAGS := -Dcustom_macro -g -c -Wall -std=c++14
  INC := -I include
  
  $(TARGET): $(OBJECTS)
      @echo " Linking..."
      $(CC) $^ -o $(TARGET) $(LIB)
  
  
  $(BUILDDIR)/%.o: $(SRCDIR)/%.$(SRCEXT)
      @mkdir -p $(BUILDDIR)
      $(CC) $(CFLAGS) $(INC) -c -o $@ $&lt;
  
  
  
  clean:
      @echo " Cleaning..."; 
      $(RM) -r $(BUILDDIR) $(TARGET)
  </code></pre>
  
  <p>The build is successful but when I run my app the code inside #ifdef custom_macro #endif is not executed but only when I change it to #ifndef .
  I also tried to set -Dcustom_macro=1 but I had the same behavior.
  I also tried to insert this with the CPPFLAGS macro as following :</p>
  
  <pre><code>CC := g++ 
  
  # Folders
  SRCDIR := src
  BUILDDIR := build
  TARGETDIR := bin
  
  # Targets
  EXECUTABLE := app
  TARGET := $(TARGETDIR)/$(EXECUTABLE)
  
  SRCEXT := cpp
  SOURCES := $(shell find $(SRCDIR) -type f -name *.$(SRCEXT))
  OBJECTS := $(patsubst $(SRCDIR)/%,$(BUILDDIR)/%,$(SOURCES:.$(SRCEXT)=.o))
  CFLAGS := -g -c -Wall -std=c++14
  CPPFLAGS := -Dcustom_macro
  INC := -I include
  
  $(TARGET): $(OBJECTS)
      @echo " Linking..."
      $(CC) $^ -o $(TARGET) $(LIB)
  
  
  $(BUILDDIR)/%.o: $(SRCDIR)/%.$(SRCEXT)
      @mkdir -p $(BUILDDIR)
      $(CC) $(CPPFLAGS) $(CFLAGS) $(INC) -c -o $@ $&lt;
  
  
  
  clean:
      @echo " Cleaning..."; 
      $(RM) -r $(BUILDDIR) $(TARGET)
  </code></pre>
  
  <p>But nothing changed. The parameters that are passed to make according to compiler are:<br>
  The parameteres that are passed to make are the following:</p>
  
  <pre><code> g++  -Dcustom_macro -g -c -Wall -std=c++14 -I include -c -o build/main.o src/main.cpp
  </code></pre>
  
  <p>Does anyone has any idea what I'm doing wrong?</p>