【发布时间】:2014-02-08 07:45:06
【问题描述】:
我正在尝试为 Windows 交叉编译一个简单的应用程序:
#include <thread>
void Func(){
return;
}
int main(){
std::thread thr1(Func);
thr1.detach();
return 0;
}
这就是我得到的:
$ i686-w64-mingw32-g++ -static-libstdc++ -static-libgcc -pipe -g -std=c++0x ./threadstutor.cpp
./threadstutor.cpp: In function ‘int main()’:
./threadstutor.cpp:8:3: error: ‘thread’ is not a member of ‘std’
./threadstutor.cpp:8:15: error: expected ‘;’ before ‘thr1’
./threadstutor.cpp:9:3: error: ‘thr1’ was not declared in this scope
其实这段代码在 Ubuntu 下用 g++ 编译是没有这个问题的;但我需要为 Windows 进行交叉编译,所以我被卡住了。
【问题讨论】:
-
如果你在 windows 上编译这个,你需要 Mingw-Builds v4.8.1 with posix-threads: sourceforge.net/projects/mingwbuilds/files/host-windows/… 你可以在 sjlj 和 seh 之间进行选择。 Seh 只是 x64,sjlj 是 x32 和 x64。
-
@CantChooseUsernames 我正在 Ubuntu 上编译它。我有来自存储库的最新 mingw; "i686-w64-mingw32-g++ --version" 说 "i686-w64-mingw32-g++ (GCC) 4.6.3"
-
@CantChooseUsernames 虽然如果我没有找到解决方案,我可以将其用作某种解决方法:通过 wine 运行 MinGW 来编译源代码。虽然很奇怪 :D 顺便问一下,我的编译器版本不支持 std::thread 的吗?
-
我不认为 4.6.3 支持 Windows 可执行文件的每个线程。我认为
std::thread在 4.7+ 时出现。也许更新可能会解决它。总是值得一试。 -
@CantChooseUsernames 我发现了一件奇怪的事情!我只是尝试下载 Windows 版本的 MinGW 并用 wine 运行它。而且......它的工作原理!版本号4.8.1,肯定比我之前尝试的版本要低。无论如何,它的作品!
标签: c++ multithreading c++11 mingw