我正在尝试编译一个简单的 C++ 程序,该程序在 eclipse kepler / mingw 4.8.1 和 win32 上使用 std::thread 。我希望在多年的 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__
构建抱怨 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不支持std::thread
。您将需要使用启用了“posix”线程的 MinGW-w64 工具链(例如 Qt 5 附带的工具链),以便 libstdc++ 公开<thread>
, <mutex>
and <future>
功能。
您可以找到安装程序here http://sourceforge.net/projects/mingwbuilds/,但您也可以尝试仅替换整个mingw
工具链根文件夹这些包之一 http://sourceforge.net/projects/mingwbuilds/files/host-windows/releases/4.8.1/。你可以选择32位或者64位,记得选择threads-posix
如果你想玩std::thread
和朋友。除了已有的编译器选项之外,不需要任何特殊的编译器选项。我建议使用-std=c++11
如果您不需要 GCC 4.6 兼容性。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)