g++ 4.8.1 C++ 线程,std::system_error - 不允许操作? [英] g++ 4.8.1 C++ Threads, std::system_error - operation not permitted?
问题描述
这不是一个重复的问题,因为提供的解决方案不适用于我的编译器.我正在尝试编译并运行以下示例 来自这个问题.
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)
这是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.
对于 g++ 4.8.1
,我需要使用不同的顺序或命令集吗?
Is there a different ordering or set of commands I need to use for g++ 4.8.1
?
推荐答案
已回答 这里
g++ -Wl,--no-as-needed -std=c++11 -pthread main.cpp -o main.out
这篇关于g++ 4.8.1 C++ 线程,std::system_error - 不允许操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!