g ++ 4.8.1 C++线程,std :: system_error - 不允许操作?

mer*_*011 6 c++ linux multithreading g++ c++11

这不是一个重复的问题,因为提供的解决方案不适用于我的编译器.我试图从这个问题编译并运行以下示例.

#include <thread>
#include <iostream>

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

我试图使用原始问题中提供的解决方案以及此复制品的已接受答案.但是,尽管我尝试了列出的所有组合,特别是尝试过

g++  main.cpp -o main.out -pthread -std=c++11
Run Code Online (Sandbox Code Playgroud)

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

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

这是输出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.
Run Code Online (Sandbox Code Playgroud)

我需要使用不同的命令或命令集g++ 4.8.1吗?

小智 10

这回答了这里

g++ -Wl,--no-as-needed -std=c++11 -pthread main.cpp -o main.out
Run Code Online (Sandbox Code Playgroud)