title: what's the differences between pthread and -pthread options in cmake?
body: <h3>Environment</h3>
  <p>ubuntu 16.04, gcc 5.4.0, cmake 3.5.1</p>
  <h2>Question</h2>
  <ol>
  <li>target_link_libraries(promise pthread)</li>
  <li>target_link_libraries(promise -pthread)</li>
  <li>target_link_libraries(promise -lpthread)</li>
  </ol>
  <p>What's the differences, which is better ?</p>
  <hr />
  <h3>Problem</h3>
  <p>promise.cpp</p>
  <pre><code>std::promise&lt;int&gt; pr;
  auto fut = pr.get_future();
  pr.set_value(10); // throw std::exception and terminate
  </code></pre>
  <p>CMakeLists.txt</p>
  <pre><code>add_executable(promise promise.cpp)
  target_link_libraries(promise pthread)
  </code></pre>
  <hr />
  <h3>Solution</h3>
  <p>Modify CMakeLists.txt slightly.</p>
  <pre><code>add_executable(promise promise.cpp)
  target_link_libraries(promise -pthread)
  </code></pre>
  <p>I found the answer from <a href="https://stackoverflow.com/questions/43928715/unknown-exception-from-stdpromise">here</a>. But I don't know why ?</p>
  <p><strong>But, the best solution is portable.</strong></p>
  <pre><code>set(THREADS_PREFER_PTHREAD_FLAG ON)
  find_package(Threads)
  target_link_libraries(promise Threads::Threads)
  </code></pre>