这不是一个重复的问题,因为提供的解决scheme不适用于我的编译器。 我想从这个问题编译并运行下面的示例。
#include <thread> #include <iostream> int main(int, char **){ std::thread tt([](){ std::cout<<"Thread!"<<std::endl; }); tt.join(); }
我曾尝试使用原始问题中提出的解决scheme以及对此重复的接受答案。 不过,尽pipe我尝试了所有列出的组合,并且特别尝试过
g++ main.cpp -o main.out -pthread -std=c++11
当我运行生成的可执行文件时,我仍然可以得到
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
的命令?
这是在这里回答
g++ -Wl,--no-as-needed -std=c++11 -pthread main.cpp -o main.out