title: how to static link with clang libc++
body: <p>I just wrote a test code for <code>coroutine</code> in c++2a.</p>
  
  <p>I build the code with clang 5.0 with: </p>
  
  <pre><code>clang++ testcoroutine.cpp -std=c++2a -I../asio_alone -fcoroutines-ts -stdlib=libc++
  </code></pre>
  
  <p>The code works fine.</p>
  
  <p>Now I want to static link the libc++.so so that I can run the a.out in other PC, I googled but only find the <code>-static-libstdc++</code>.</p>
  
  <p>I can not use the <code>-static-libstdc++</code> because the <code>libstdc++</code> does not support the <code>coroutine</code>.</p>
  
  <p>If I use the -static-libstdc++:</p>
  
  <pre><code>clang++ testcoroutine.cpp -std=c++2a -I../asio_alone -fcoroutines-ts
  -static-libstdc++ 
  testcoroutine.cpp:26:10: fatal error: 'experimental/coroutine' file not found
  #include &lt;experimental/coroutine&gt;
  
  
   ^~~~~~~~~~~~~~~~~~~~~~~~ 1 error generated.
  </code></pre>
  
  <hr>
  
  <p>Any suggestion?</p>
  
  <hr>
  
  <p>The test code:</p>
  
  <pre><code>#define ASIO_STANDALONE
  #define ASIO_HAS_STD_CHRONO
  
  #ifdef _WIN32
  #pragma warning (disable:4819)
  #pragma warning (disable:4503)
  #pragma warning (disable:4996)
  #pragma warning (disable:4100) // unref parameters
  #define _CRT_SECURE_NO_WARNINGS
  #define NOMINMAX
  #define _CRT_NONSTDC_NO_DEPRECATE
  #define WIN32_LEAN_AND_MEAN
  #endif
  
  #ifdef _WIN32
  #include &lt;SDKDDKVer.h&gt;
  #endif
  
  #include &lt;stdio.h&gt;
  #include &lt;cstdio&gt;
  #include &lt;thread&gt;
  #include &lt;algorithm&gt;
  #include &lt;future&gt;
  #include &lt;chrono&gt;
  #include &lt;experimental/coroutine&gt;
  #include &lt;asio.hpp&gt;
  
  // clang++ testcoroutine.cpp -std=c++2a -I../asio_alone -fcoroutines-ts -stdlib=libc++
  
  #ifndef _WIN32
  template &lt;typename... Args&gt;
  struct std::experimental::coroutine_traits&lt;std::future&lt;void&gt;, Args...&gt; {
      struct promise_type {
          std::promise&lt;void&gt; p;
          auto get_return_object() { return p.get_future(); }
          std::experimental::suspend_never initial_suspend() { return {}; }
          std::experimental::suspend_never final_suspend() { return {}; }
          void set_exception(std::exception_ptr e) { p.set_exception(std::move(e)); }
          void return_void() { p.set_value(); }
          void unhandled_exception() { std::terminate(); }
      };
  };
  #endif 
  
  template &lt;typename R, typename P&gt;
  auto async_await(asio::steady_timer &amp;t, std::chrono::duration&lt;R, P&gt; d) {
      struct Awaiter {
          asio::steady_timer &amp;t;
          std::chrono::duration&lt;R, P&gt; d;
          asio::error_code ec;
  
          bool await_ready() { return d.count() == 0; }
          void await_resume() {
              if (ec)
                  throw ec;
          }
          void await_suspend(std::experimental::coroutine_handle&lt;&gt; coro) {
              t.expires_from_now(d);
              t.async_wait([this, coro](auto ec) mutable {
                  this-&gt;ec = ec;
                  coro.resume();
              });
          }
      };
      return Awaiter{ t, d };
  }
  
  
  std::future&lt;void&gt; sleepy(asio::io_service &amp;io) {
      asio::steady_timer timer(io);
      co_await async_await(timer, std::chrono::milliseconds(100));
      puts("tick1");
      co_await async_await(timer, std::chrono::milliseconds(100));
      puts("tick2");
      co_await async_await(timer, std::chrono::milliseconds(100));
      puts("tick3");
  }
  
  int main()
  {      
      asio::io_service io;
      sleepy(io);
      io.run();
      return 0;
  }
  </code></pre>