3

Windows用のLinuxで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)

よろしくケビン

4

3 に答える 3

1

基本的に、MinGW は Windows 上のスレッドをサポートしていません。次のリンクを参照してください: http://www.cplusplus.com/forum/windows/82461/

具体的には、_GLIBCXX_HAS_GTHREADS が定義されておらず、ヘッダー スレッドのクラス スレッドがそれを必要としています。(gthreads 上に構築されています)。

win/linux 互換のスレッド クラスには、boost::thread を試して使用する必要があります。

于 2013-10-29T20:23:24.867 に答える
-1

ほとんどの場合、スレッドヘッダーを含めるのを忘れている可能性があります#include <thread>

于 2013-09-23T12:58:03.320 に答える