C ++ 0x“Hello Concurrent World”会立即在g ++ / linux上发生段错误吗?

时间:2010-08-07 21:05:45

标签: c++ linux multithreading c++11

在C ++ 0x书中浏览货币并认为我会给示例代码一个运行。这是基本的。

#include <iostream>
#include <thread>

void hello()
{
    std::cout<<"Hello Concurrent World\n";
}


int main(int argc, char *argv[])
{
    std::thread t(hello);

    t.join();
}

编译:

g++ -std=c++0x -g -o pgm pgm.cpp

热潮:

Program received signal SIGSEGV, Segmentation fault.
_dl_fixup (l=0x7ffff7b0992c, reloc_arg=<value optimized out>) at ../elf/dl-runtime.c:147
147     ../elf/dl-runtime.c: No such file or directory.
        in ../elf/dl-runtime.c

似乎是某种设置/库问题。有谁熟悉这个?

1 个答案:

答案 0 :(得分:20)

您需要使用-pthread标记进行编译/链接。