线程不是使用Eclipse Kepler MinGW的命名空间std的成员 我试图编译一个简单的C++程序,它使用了在Eclipse KePux/MinW4.4.1和Win32上的STD::Type。在windows开发多年后,我希望在某个时候将开发转移到linux #include "test.h" #include <thread> #include <algorithm> int main() { Test::CreateInstance(); std::thread( [&]() { Test::I()->Output2(); } ); Test::DestroyInstance(); return 0; }

线程不是使用Eclipse Kepler MinGW的命名空间std的成员 我试图编译一个简单的C++程序,它使用了在Eclipse KePux/MinW4.4.1和Win32上的STD::Type。在windows开发多年后,我希望在某个时候将开发转移到linux #include "test.h" #include <thread> #include <algorithm> int main() { Test::CreateInstance(); std::thread( [&]() { Test::I()->Output2(); } ); Test::DestroyInstance(); return 0; },c++,eclipse,multithreading,c++11,mingw,C++,Eclipse,Multithreading,C++11,Mingw,我定义的预处理器符号是: __GXX_EXPERIMENTAL_CXX0X__ 建筑物抱怨std::thread不是std: 10:30:13 **** Incremental Build of configuration Debug for project test **** Info: Internal Builder is used for build g++ -D__GXX_EXPERIMENTAL_CXX0X__ -O0 -g3 -Wall -c -fmessage-leng

我定义的预处理器符号是:

__GXX_EXPERIMENTAL_CXX0X__
建筑物抱怨std::thread不是std:

    10:30:13 **** Incremental Build of configuration Debug for project test ****
Info: Internal Builder is used for build
g++ -D__GXX_EXPERIMENTAL_CXX0X__ -O0 -g3 -Wall -c -fmessage-length=0 -std=c++0x -Wc++0x-compat -o main.o "..\\main.cpp" 
..\main.cpp: In function 'int main()':
..\main.cpp:11:2: error: 'thread' is not a member of 'std'
  std::thread(
  ^

有人能告诉我正确编译时可能缺少什么吗?

Plain MinGW无法支持
std::thread
。您需要使用启用了“posix”线程的MinGW-w64工具链(如Qt5附带的工具链),以便libstdc++公开
功能


您可以找到安装程序,但也可以尝试将整个
mingw
工具链根文件夹替换为。您可以选择32位或64位,如果您想玩
std::thread
和friends,请记住选择
threads posix
。除了您已有的编译器选项外,不需要其他特殊的编译器选项。如果您不需要GCC4.6兼容性,我建议您使用
-std=c++11

我也有同样的问题,尽管我使用的是Cygwin编译器。我所做的是用预处理器的值
201103L
定义符号
\uuu cplusplus
。我还为编译器使用了标志
-std=c++11
。必须对所有配置(调试和发布)进行此设置


您可以检查的另一件事是,您已经正确安装了编译器,请按照rubenvb的说明验证您的编译器安装。

有关可以添加到任何C++11版本的MinGW的本机实现,请参见此处:
它是一个只包含头的库,因此您只需要在项目中包含头,就可以获得C++11线程和同步原语。

您使用的是哪个版本的
MinGW
?而且
pthread`也需要链接吗?我使用的是mingwv4.8.1。我认为我没有使用pthreads。我以为我在用std::thread?它们是一样的吗?这不是编译器支持的问题,编译器不知道也不关心线程。缺少实现的是标准库。有关本机轻量级解决方案,请参见下面的答案,而不是在Windows上使用pthread仿真。
-std=c++11
应相应地设置
\uucplusplus
。您不应该自己设置
\u cplusplus
    10:30:13 **** Incremental Build of configuration Debug for project test ****
Info: Internal Builder is used for build
g++ -D__GXX_EXPERIMENTAL_CXX0X__ -O0 -g3 -Wall -c -fmessage-length=0 -std=c++0x -Wc++0x-compat -o main.o "..\\main.cpp" 
..\main.cpp: In function 'int main()':
..\main.cpp:11:2: error: 'thread' is not a member of 'std'
  std::thread(
  ^