title: Why does my makefile call gcc although I set CC=g++?
body: <p>I have a small code that compiles with <code>g++ -std=c++17 -Wall -Og -g -o main *.cc</code> perfectly. Now I want tor have a makefile and so far I got this:</p>
  
  <pre><code>CC = g++
  CFLAGS = -Wall -std=c++17 -Og -g
  DEPS = random_tools.h
  OBJ = main.o random_tools.o
  
  %.o: %.c $(DEPS)
      $(CC) $(CFLAGS) -o $@ $&lt;
  
  main: $(OBJ)
      gcc $(CFLAGS) -o $@ $^
  </code></pre>
  
  <p>However, when I run <code>make</code> it crashes, telling me </p>
  
  <pre><code>g++    -c -o main.o main.cc
  g++    -c -o random_tools.o random_tools.cc
  gcc -Wall -o main main.o random_tools.o
  main.o: In function `main':
  main.cc:(.text+0x1d): undefined reference to `std::cout'
  main.cc:(.text+0x22): undefined reference to `std::ostream::operator&lt;&lt;(int)'
  main.cc:(.text+0x27): undefined reference to `std::basic_ostream&lt;char, std::char_traits&lt;char&gt; &gt;&amp; std::endl&lt;char, std::char_traits&lt;char&gt; &gt;(std::basic_ostream&lt;char, std::char_traits&lt;char&gt; &gt;&amp;)'
  main.cc:(.text+0x2f): undefined reference to `std::ostream::operator&lt;&lt;(std::ostream&amp; (*)(std::ostream&amp;))'
  main.o: In function `__static_initialization_and_destruction_0(int, int)':
  main.cc:(.text+0x5d): undefined reference to `std::ios_base::Init::Init()'
  main.cc:(.text+0x6c): undefined reference to `std::ios_base::Init::~Init()'
  collect2: error: ld returned 1 exit status
  make: *** [makefile:10: main] Error 1
  </code></pre>
  
  <p>What I really don't get is why it uses <code>gcc</code> instead of <code>g++</code> - I am telling it to use <code>g++</code>. Can somebody shed light on what happens here and how I can make <code>make</code> do what I say? Thanks.</p>