g ++ 4.8.1 C ++ Threads,std :: system_error - 不允许操作? [英] g++ 4.8.1 C++ Threads, std::system_error - operation not permitted?

查看:329
本文介绍了g ++ 4.8.1 C ++ Threads,std :: system_error - 不允许操作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这不是一个重复的问题,因为提出的解决方案不工作我的编译器。我试图编译并运行以下示例

  #include< thread> 
#include< iostream>

int main(int,char **){
std :: thread tt([](){std :: cout<<Thread!< std: :endl;});
tt.join();
}

我试图使用原始问题中提供的解决方案,已接受的此重复答案。但是,尽管我尝试了所有的组合,特别是尝试

  g ++ main.cpp -o main.out -pthread  - std = c ++ 11 



当我运行生成的可执行文件时,我仍然得到

  terminate在抛出'std :: system_error'实例后调用
what():启用多线程以使用std :: thread:Operation不允许
中止(内核转储)

这里是 g ++ --version

  g ++(Ubuntu / Linaro 4.8.1-10ubuntu9) 1 
版权所有(C)2013自由软件基金会,
这是免费软件;请参阅复制条件的来源。有NO
保修;甚至不适用于适销性或特定用途的适用性。

g ++是否需要使用不同的顺序或命令集 com / questions / 19463602 / compiling-multithread-code-with-g>这里

  g ++ -Wl, --no-as-need -std = c ++ 11 -pthread main.cpp -o main.out 


This is not a duplicate question, because the solutions presented are not working on my compiler. I am trying to compile and run the following example from this question.

#include <thread>
#include <iostream>

int main(int, char **){
    std::thread tt([](){ std::cout<<"Thread!"<<std::endl; });
    tt.join();
}

I have attempted to use the solutions presented in both that original question as well as the accepted answer to this duplicate. However, although I tried all the combinations listed, and in particular tried

g++  main.cpp -o main.out -pthread -std=c++11

When I run the resulting executable, I still get

terminate called after throwing an instance of 'std::system_error'
  what():  Enable multithreading to use std::thread: Operation not permitted
Aborted (core dumped)

Here is the output of g++ --version.

g++ (Ubuntu/Linaro 4.8.1-10ubuntu9) 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.

Is there a different ordering or set of commands I need to use for g++ 4.8.1?

解决方案

this was answered here

g++ -Wl,--no-as-needed -std=c++11 -pthread main.cpp -o main.out

这篇关于g ++ 4.8.1 C ++ Threads,std :: system_error - 不允许操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆