linux下编译c++程序遇到 error: ‘thread’ is not a member of ‘std’的错误

来源:互联网 发布:淘宝的需求分析报告 编辑:程序博客网 时间:2024/06/05 19:32
今天用c++写了一个socket网络编程,用 g++ client.c -o client  命令编译时出现“client.c:69:5: error: ‘thread’ is not a member of ‘std’

     std::thread(RMsg).detach();”  的错误,在网上搜索原因,看到了一个外国论坛上老外给出的答案:" To get g++ into C++11(or C++0x) mode, you have to add the command-line parameter    -std=c++0x  on versions <=4.6 ,  nowadays you can also use   -std=c++11 ."

按照此方法我在g++ client.c -o client 命令后面加上-std=c++11,最终编译成功。

不加参数-std=c++11编译之所以会出现错误,是因为GCC/G++默认的-std(即C++语言标准)不是C++11,在这里默认的是C++98,所以需要显式地开启,即添加-std=c++11参数。

0 0
原创粉丝点击