我使用macports编译并安装了gcc4.4。
当我尝试使用-> g++ -g -Wall -ansi -pthread -std=c++0x main.cpp进行编译时:
#include <thread>
...
std::thread t(handle);
t.join();
....编译器返回:
cserver.cpp: In member function 'int CServer::run()':
cserver.cpp:48: error: 'thread' is not a member of 'std'
cserver.cpp:48: error: expected ';' before 't'
cserver.cpp:49: error: 't' was not declared in this scope但是std::cout <<...编译得很好..
有谁可以帮我?
发布于 2010-03-26 05:50:46
丢弃-ansi,它的意思是-std=c++98,这显然不是你想要的。它还会导致定义宏__STRICT_ANSI__,这可能会改变标头的行为,例如,通过禁用C++0x支持。
发布于 2016-12-01 03:49:07
我在使用MinGW的windows上也遇到了同样的问题。我在github mingw-std-threads上找到了中的包装器类,包括全局MinGW目录下的mingw.mutex.h和mingw.thread.h文件,修复了这个问题。我所要做的就是包含头文件,代码保持不变
#include "mingw.thread.h"
...
std::thread t(handle);
...https://stackoverflow.com/questions/2519607
复制相似问题