简体   繁体   English

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

[英]C++0x “Hello Concurrent World” immediately segfaults on g++/linux?

Browsing through a Currency in C++0x book and thought I would give the sample code a run. 浏览C ++ 0x书中的货币并认为我会给出示例代码。 It is as basic as it gets. 它是基本的。

#include <iostream>
#include <thread>

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


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

    t.join();
}

Compiled with: 编译:

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

Goes boom with: 热潮:

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

Appears to be a setup/library issue of some kind. 似乎是某种设置/库问题。 Anyone familiar with this? 有人熟悉这个吗?

您需要使用-pthread标志编译/链接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM