linux 学习

最近在学习linux,用的是VMware player 下的Ubuntu 14.04.初试一段小代码test.cpp,然后编译 g++ test.cpp  之后出来的结果是我需要设置-std=c++11

或者-std=gnu++11选项,后来采用 g++ -std=c++11 test.cpp 进行编译,但是编译是通过了,接着问题又来了,运行./test 出现了

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


这样一堆问题,最后不停滴百度,有人说用g++ -o test test.cpp -pthread -std=c++11 来进行编译,试过之后,发现这样编译后生成的文件是可执行的。即编译和链接时都指定-pthread

#include <thread>
#include <iostream>
void my_thread()
{
puts("hello, world");
}

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

system("pause");
return 0;
}

posted @ 2015-07-18 11:34  游云惊帆  阅读(179)  评论(0编辑  收藏  举报