title: std::future and clang with -stdlib=libstdc++
body: <p>The following program fails to link with clang and -stdlib=libstdc++:</p>
  
  <pre><code>$ cat future.cpp
  #include &lt;iostream&gt;
  #include &lt;future&gt;
  
  int main()
  {
    std::future&lt;int&gt; f1 = std::async([](){ return 42; });
    f1.wait();
    std::cout &lt;&lt; "Magic number is: " &lt;&lt; f1.get() &lt;&lt; std::endl;
  }
  $ g++-mp-5 future.cpp -std=c++11 &amp;&amp; ./a.out
  Magic number is: 42
  $ clang++-mp=3.5 future.cpp -std=c++11 &amp;&amp; ./a.out
  Magic number is: 42
  </code></pre>
  
  <p>When building with clang and -stdlib=libstdc++, the following linking error occurs:</p>
  
  <pre><code>$ clang++-mp-3.5  future.cpp -std=c++11 -stdlib=libstdc++ -I/opt/local/include/gcc5/c++ -I/opt/local/include/gcc5/c++/x86_64-apple-darwin14 -L/opt/local/lib/gcc5 -lstdc++ &amp;&amp; ./a.out 
  Undefined symbols for architecture x86_64:
    "std::__once_call", referenced from:
        void std::call_once&lt;void (std::__future_base::_State_baseV2::*)(std::function&lt;std::unique_ptr&lt;std::__future_base::_Result_base, std::__future_base::_Result_base::_Deleter&gt; ()&gt;*, bool*), std::__future_base::_State_baseV2*, std::function&lt;std::unique_ptr&lt;std::__future_base::_Result_base, std::__future_base::_Result_base::_Deleter&gt; ()&gt;*, bool*&gt;(std::once_flag&amp;, void (std::__future_base::_State_baseV2::*&amp;&amp;)(std::function&lt;std::unique_ptr&lt;std::__future_base::_Result_base, std::__future_base::_Result_base::_Deleter&gt; ()&gt;*, bool*), std::__future_base::_State_baseV2*&amp;&amp;, std::function&lt;std::unique_ptr&lt;std::__future_base::_Result_base, std::__future_base::_Result_base::_Deleter&gt; ()&gt;*&amp;&amp;, bool*&amp;&amp;) in future-b6480b.o
        void std::call_once&lt;void (std::thread::*)(), std::reference_wrapper&lt;std::thread&gt; &gt;(std::once_flag&amp;, void (std::thread::*&amp;&amp;)(), std::reference_wrapper&lt;std::thread&gt;&amp;&amp;) in future-b6480b.o
    "std::__once_callable", referenced from:
        void std::call_once&lt;void (std::__future_base::_State_baseV2::*)(std::function&lt;std::unique_ptr&lt;std::__future_base::_Result_base, std::__future_base::_Result_base::_Deleter&gt; ()&gt;*, bool*), std::__future_base::_State_baseV2*, std::function&lt;std::unique_ptr&lt;std::__future_base::_Result_base, std::__future_base::_Result_base::_Deleter&gt; ()&gt;*, bool*&gt;(std::once_flag&amp;, void (std::__future_base::_State_baseV2::*&amp;&amp;)(std::function&lt;std::unique_ptr&lt;std::__future_base::_Result_base, std::__future_base::_Result_base::_Deleter&gt; ()&gt;*, bool*), std::__future_base::_State_baseV2*&amp;&amp;, std::function&lt;std::unique_ptr&lt;std::__future_base::_Result_base, std::__future_base::_Result_base::_Deleter&gt; ()&gt;*&amp;&amp;, bool*&amp;&amp;) in future-b6480b.o
        void std::__once_call_impl&lt;std::_Bind_simple&lt;std::_Mem_fn&lt;void (std::__future_base::_State_baseV2::*)(std::function&lt;std::unique_ptr&lt;std::__future_base::_Result_base, std::__future_base::_Result_base::_Deleter&gt; ()&gt;*, bool*)&gt; (std::__future_base::_State_baseV2*, std::function&lt;std::unique_ptr&lt;std::__future_base::_Result_base, std::__future_base::_Result_base::_Deleter&gt; ()&gt;*, bool*)&gt; &gt;() in future-b6480b.o
        void std::call_once&lt;void (std::thread::*)(), std::reference_wrapper&lt;std::thread&gt; &gt;(std::once_flag&amp;, void (std::thread::*&amp;&amp;)(), std::reference_wrapper&lt;std::thread&gt;&amp;&amp;) in future-b6480b.o
        void std::__once_call_impl&lt;std::_Bind_simple&lt;std::_Mem_fn&lt;void (std::thread::*)()&gt; (std::reference_wrapper&lt;std::thread&gt;)&gt; &gt;() in future-b6480b.o
  ld: symbol(s) not found for architecture x86_64
  clang: error: linker command failed with exit code 1 (use -v to see invocation)
  </code></pre>
  
  <p>However, a simple program w/o <code>future</code> builds just fine, e.g.:</p>
  
  <pre><code>$ cat simple.cpp
  #include &lt;iostream&gt;
  #include &lt;future&gt;
  
  int main()
  {
    std::cout &lt;&lt; "Magic number is: " &lt;&lt; 42 &lt;&lt; std::endl;
  }
  $ clang++-mp-3.5  simple.cpp -std=c++11 -stdlib=libstdc++ -I/opt/local/include/gcc5/c++ -I/opt/local/include/gcc5/c++/x86_64-apple-darwin14 -L/opt/local/lib/gcc5 -lstdc++ &amp;&amp; ./a.out 
  Magic number is: 42
  </code></pre>
  
  <p>System is OSX 10.10.4 with macports. </p>
  
  <p>I can't figure out what is the problem. Thanks!   </p>