std::thread works in cygwin but not in MinGw

后端 未结 2 1465
南方客
南方客 2020-12-22 04:19

So I decided to give c++ a try today. I downloaded MinGw and the g++ compiler that comes with it. I decided to test the following code:

#include 

        
相关标签:
2条回答
  • 2020-12-22 04:58

    MinGW-w64 (or rather GCC on windows) needs to be compiled with posix thread support if you want to use std::thread, presumably you downloaded a build with native windows threads.

    Check out the mingw-builds folders targeting 64 bit or 32 bit and pick a version with posix threads. You'll also need to choose the exception handling method, if you don't have a reason to choose otherwise then stick with the GCC defaults of seh for 64 bit and dwarf for 32.

    0 讨论(0)
  • I tested this in linux (cross-compiling).

    This compiles ok,

    i686-w64-mingw32-g++-posix -std=c++11 threads.cpp -lwinpthread
    

    this does not

    i686-w64-mingw32-g++-win32 -std=c++11 threads.cpp -lwinpthread
    

    The difference between the compilers is --enable-threads=win32 vs. --enable-threads=posix option used when the compilers were built. g++ -v should show what was used.

    0 讨论(0)
提交回复
热议问题