title: Compiling multithread code with g++
body: <p>I have the easiest code ever:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;thread&gt;
  
  void worker()
  {
      std::cout &lt;&lt; "another thread";
  }
  
  int main()
  {
      std::thread t(worker);
      std::cout &lt;&lt; "main thread" &lt;&lt; std::endl;
      t.join();
      return 0;
  }
  </code></pre>
  
  <p>though I still cannot compile it with <code>g++</code> to run.</p>
  
  <p>More details:</p>
  
  <pre><code>$ g++ --version
  g++ (Ubuntu/Linaro 4.8.1-10ubuntu8) 4.8.1
  Copyright (C) 2013 Free Software Foundation, Inc.
  This is free software; see the source for copying conditions.  There is NO
  warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  </code></pre>
  
  <p>Command to compile:</p>
  
  <pre><code>$ g++ main.cpp -o main.out -pthread -std=c++11
  </code></pre>
  
  <p>Running:</p>
  
  <pre><code>$ ./main.out 
  terminate called after throwing an instance of 'std::system_error'
    what():  Enable multithreading to use std::thread: Operation not permitted
  Aborted (core dumped)
  </code></pre>
  
  <p>And now I'm in stuck. In every related thread over the internet it's recommended to add <code>-pthread</code> while I have it already.</p>
  
  <p>What am I doing wrong?</p>
  
  <p>PS: It's a brand new ubuntu 13.10 installation. Only <code>g++</code> package was installed and minor things like <code>chromium</code> etc</p>
  
  <p>PPS:</p>
  
  <pre><code>$ ldd ./a.out 
  linux-vdso.so.1 =&gt; (0x00007fff29fc1000) 
  libstdc++.so.6 =&gt; /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fb85397d000) 
  libgcc_s.so.1 =&gt; /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fb853767000) 
  libc.so.6 =&gt; /lib/x86_64-linux-gnu/libc.so.6 (0x00007fb85339e000) 
  libm.so.6 =&gt; /lib/x86_64-linux-gnu/libm.so.6 (0x00007fb85309a000) 
  /lib64/ld-linux-x86-64.so.2 (0x00007fb853c96000)
  </code></pre>
  
  <p>PPPS: with <code>clang++</code> (v3.2) it compiles and runs fine</p>
  
  <p>PPPPS: guys, it's not a duplicate of <a href="https://stackoverflow.com/questions/8649828/what-is-wrong-with-this-use-of-stdthread">What is the correct link options to use std::thread in GCC under linux?</a></p>
  
  <p>PPPPPS:</p>
  
  <pre><code>$ dpkg --get-selections | grep 'libc.*dev'
  libc-dev-bin                    install
  libc6-dev:amd64                 install
  libclang-common-dev             install
  linux-libc-dev:amd64                install
  </code></pre>