title: Forcing Clang to link with C++ runtime
body: <p>I have a project containing a mixture of C and C++ source. It currently builds with GCC on OS X. The project has bespoke build scripts which invoke the <code>gcc</code> command to compile both the C and C++ source, and separately invoke the linker.</p>
  
  <p>I am now trying to get it building with Clang. </p>
  
  <p>Invoking <code>clang</code> does compile the source files correctly; it distinguishes between <code>.c</code> and <code>.cpp</code> source files, and compiles for the appropriate language in each case. I have problems at link time, though. When the linker is invoked as <code>clang</code>, the C++ runtime libraries are not linked in, causing a build error due to missing symbols.</p>
  
  <p>I can link successfully when I set <code>clang++</code> as the build tool, but this then causes compile-time errors and warnings; it really doesn't like compiling C source with the C++ compiler.</p>
  
  <pre><code>clang: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated
  ...
  /usr/include/stdio.h:250:49: error: redefinition of parameter 'restrict'
  </code></pre>
  
  <p><strong>I have to specify a single tool for the build scripts to use as the compiler/linker</strong>, so I need to do a simple substitution of <code>clang</code> in place of <code>gcc</code>.
  Is there any way I can persuade <code>clang</code> (not <code>clang++</code>) to link with the C++ runtime libraries?</p>
  
  <p>Options such as <code>-stdlib=libc++</code> don't work.</p>