【发布时间】:2013-09-20 09:42:38
【问题描述】:
我正在尝试在 eclipse kepler / mingw 4.8.1 和 win32 上编译一个使用 std::thread 的简单 c++ 程序。我希望在 Windows 开发多年后的某个时候将开发转移到 linux。
#include "test.h"
#include <thread>
#include <algorithm>
int main()
{
Test::CreateInstance();
std::thread(
[&]()
{
Test::I()->Output2();
}
);
Test::DestroyInstance();
return 0;
}
忽略测试的目的(它是一个单例,它只产生一些输出,一旦我让 std::thread 工作,我将对其进行扩展!)
我在 Eclipse 中设置的 g++ 编译器设置是:
-c -fmessage-length=0 -std=c++0x -Wc++0x-compat
我定义的预处理器符号是:
__GXX_EXPERIMENTAL_CXX0X__
Building 抱怨 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(
^
有人可以建议我可能缺少什么来正确编译吗?
【问题讨论】:
-
您使用的是哪个版本的
MinGW?还有 dont you have to link againstpthread` 吗? -
我正在使用 mingw v4.8.1。我不认为我在使用 pthreads。我以为我在使用 std::thread?它们是一样的吗?
标签: c++ eclipse multithreading c++11 mingw