clang で std::thread を使う際はコンパイルオプションに -stdlib=libc++ も必要

clang で std::thread を使う際はコンパイルオプションに -stdlib=libc++ も必要

先日,作業してて詰まったのでメモ書き.

clang で std::thread を使う際はコンパイルオプションに -std=c++11 だけではなく -stdlib=libc++ も必要でした.

$ clang++-mp-3.3 thread.cpp -std=c++11 -stdlib=libc++

サンプルコード

試しに次のソースコードコンパイル

/**----------
   thread.cpp
   ----------*/

#include <iostream>
#include <thread>

void f(void){
  std::cout << "f(): " << std::this_thread::get_id() 
	    << std::endl;
}

int main(void){
  std::thread th(f);

  th.join();

  return 0;
}

コンパイル方法は次の通り.

$ clang++-mp-3.3 thread.cpp -std=c++11 -stdlib=libc++

実行結果

$ ./a.out 
f(): 0x103952000