在Linux上使用MinGW进行交叉编译C++11线程

3

我尝试在Linux上使用mingw将一些C++11源代码交叉编译为Windows。该代码使用了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++编译时没有任何问题。

谢谢,

问候, Kevin

-编辑-

我刚刚从互联网上下载了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)

问候
凯文


gcc在mingw上支持C++11线程吗? - Duck
你使用的MinGW GCC版本是哪个?../mingw/cross/bin/i686-w64-mingw32-g++ -v的输出是什么?在Linux系统上进行交叉编译通常更容易(因此可以在您的计算机上安装Linux)。 - Basile Starynkevitch
我刚刚在起始帖子中写了版本输出。我总是使用Linux进行交叉编译:-)现在也是如此。我使用的是Xubuntu。谢谢你的帮助。 - Kevin Meier
可能是重复问题 std::thread在使用Eclipse Kepler MinGW时不在命名空间std中。虽然不完全一样,但它有相同的答案。 - rubenvb
3个回答

2

1

基本上,MinGW在Windows上不支持线程,请参考以下链接: http://www.cplusplus.com/forum/windows/82461/

具体来说,_GLIBCXX_HAS_GTHREADS未定义,并且头文件thread中的类thread需要它。 (它是建立在gthreads之上的)。

您应该尝试使用boost :: thread作为win / linux兼容的线程类。


-1

很可能您忘记了包含线程头文件 #include <thread>


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接