title: gcc compiling C++ code: undefined reference to `operator new[](unsigned long long)'
body: <p>There's a C++ code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  int main() {
  
  int b = sizeof('a');
  if(b==4) printf("I'm a C program!\n");
  else printf("I'm a C++ program!\n");
  }
  </code></pre>
  
  <p>Compile it like this:</p>
  
  <pre><code>gcc main.cpp -o main
  </code></pre>
  
  <p>It succeeds and gives:</p>
  
  <pre><code>I'm a C++ program!
  </code></pre>
  
  <p>Then add a line somewhere inside function <code>main</code></p>
  
  <pre><code>int *p1 = new int [1000];
  </code></pre>
  
  <p>It fails with:</p>
  
  <pre><code>C:\Users\...\AppData\Local\Temp\cccJZ8kN.o:main1.cpp:(.text+0x1f): undefined reference to operator new[](unsigned long long)'
  collect2.exe: error: ld returned 1 exit status
  </code></pre>
  
  <p>Then the following two commands successfully compile the code:</p>
  
  <pre><code>gcc main.cpp -o main -lstdc++
  </code></pre>
  
  <p>and</p>
  
  <pre><code>g++ main.cpp -o main
  </code></pre>
  
  <p>The compiler is minGW-win64 (<a href="http://mingw-w64.sourceforge.net/" rel="noreferrer">http://mingw-w64.sourceforge.net/</a>).</p>
  
  <p><strong>The questions are:</strong></p>
  
  <ol>
  <li>Which of the two last commands are better?</li>
  <li>To my mind <code>gcc</code> correctly chooses the right compiler but then uses a wrong linker. Is it right?</li>
  <li>May it be a problem in minGW-win64?</li>
  </ol>
  
  <p>As I see (correct me if it's wrong) <code>gcc</code> was intended to be a main program that takes the input and decides what to do with it. So I'd better use <code>gcc</code> if it worked without <code>-lstdc++</code>. But if it's not possible I'll prefer using <code>g++</code> instead as don't know what else <code>gcc</code> may miss.</p>
  
  <p>Many thanks for your considerations</p>