C++ mutex in namespace std does not name a type

前端 未结 11 909
日久生厌
日久生厌 2020-11-28 13:22

I\'m writing a simple C++ program to demonstrate the use of locks. I am using codeblocks and gnu gcc compiler.

 #inclu         


        
11条回答
  •  孤城傲影
    2020-11-28 14:01

    I happened to be looking at the same problem. GCC works fine with std::mutex under Linux. However, on Windows things seem to be worse. In the header file shipped with MinGW GCC 4.7.2 (I believe you are using a MinGW GCC version too), I have found that the mutex class is defined under the following #if guard:

    #if defined(_GLIBCXX_HAS_GTHREADS) && defined(_GLIBCXX_USE_C99_STDINT_TR1)
    

    Regretfully, _GLIBCXX_HAS_GTHREADS is not defined on Windows. The runtime support is simply not there.

    You may also want to ask questions directly on the MinGW mailing list, in case some GCC gurus may help you out.

    EDIT: The MinGW-w64 projects provides the necessary runtime support. Check out http://mingw-w64.sourceforge.net/ and https://sourceforge.net/projects/mingw-w64/files/. Also, as 0xC0000022L pointed out, you need to download the POSIX thread version (I missed mentioning it last time).

提交回复
热议问题