linux - 在 linux 上使用 mingw 交叉编译 c++11 线程

标签 linux windows multithreading c++11 mingw

我尝试在 linux for windows 上使用 mingw 交叉编译一些 c++11 源代码。代码使用 std::thread。

当我编译时,我总是会遇到一些错误:

$ ../mingw/cross/bin/i686-w64-mingw32-g++  -std=c++11 -I include/ test.cpp -lstdthread -otest
In file included from test.cpp:4:0:
...
error: 'thread' in namespace 'std' does not name a type
...

我可以在 mingw 中启用 c++11 线程吗?使用本地 g++ 编译代码没有任何问题。

谢谢,

问候 凯文

-编辑-

我刚刚在互联网上的某个地方下载了 mingw,因为我试图获得一个尽可能新的版本:

../mingw/cross/bin/i686-w64-mingw32-g++  -v
Using built-in specs.
COLLECT_GCC=../mingw/cross/bin/i686-w64-mingw32-g++
COLLECT_LTO_WRAPPER=/home/bmeier/source/mingw/cross/bin/../libexec/gcc/i686-w64-mingw32/4.8.1/lto-wrapper
Target: i686-w64-mingw32
Configured with: /home/drangon/work/mingw-w64-dgn_32/source/gcc-4.8.1/configure --target=i686-w64-mingw32 --disable-nls --disable-multilib --with-gmp=/home/drangon/work/mingw-w64-dgn_32/build/for_cross --with-mpfr=/home/drangon/work/mingw-w64-dgn_32/build/for_cross --with-mpc=/home/drangon/work/mingw-w64-dgn_32/build/for_cross --with-isl=/home/drangon/work/mingw-w64-dgn_32/build/for_cross --with-cloog=/home/drangon/work/mingw-w64-dgn_32/build/for_cross --enable-languages=c,c++,objc,obj-c++ --disable-libstdcxx-pch --prefix=/home/drangon/work/mingw-w64-dgn_32/cross --with-sysroot=/home/drangon/work/mingw-w64-dgn_32/cross
Thread model: win32
gcc version 4.8.1 (GCC)

问候 凯文

最佳答案

已经有 std::thread 和同步原语的原生实现,适用于任何 C++11 版本的 MinGW: https://github.com/meganz/mingw-std-threads

关于linux - 在 linux 上使用 mingw 交叉编译 c++11 线程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17625306/

相关文章:

linux - 获取包含 "typeset -r VAR=value"的 shell 脚本

linux - 如何在 AWK 中将字段分隔符设置为 ^@(特殊字符)?

linux - 我可以核心转储一个阻塞磁盘事件的进程(最好不要杀死它)吗?

windows - 在Windows 7中获取本地端口号

c# - 事件对象模式的 .NET 实现

java - 连接被拒绝错误 Java/Linux

windows - 为分析设置 CPU 亲和性

c++ - 如何通过调用类中的函数来创建线程?

c - 循环线程访问 pthread mutex

java - 在 java 中获取所有 java 运行进程 PID 的热门方法?