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

今天用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参数。

你可能感兴趣的:(linux下编译c++程序遇到 error: ‘thread’ is not a member of ‘std’的错误)