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

前端 未结 11 906
日久生厌
日久生厌 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 13:57

    I don't know if it works for everybody, but in other way you just have to update your ndk. I'm using ndk-r11c and it works perfectly.

    0 讨论(0)
  • 2020-11-28 13:58

    Mutex, at least, is not supported in 'Thread model: win32' of the Mingw-builds toolchains. You must select any of the toolchains with 'Thread model: posix'. After trying with several versions and revisions (both architectures i686 and x86_64) I only found support in x86_64-4.9.2-posix-seh-rt_v3-rev1 being the thread model, IMO, the determining factor.

    0 讨论(0)
  • 2020-11-28 13:58

    my gcc version is 5.4 and i solved this problem when adding #include and also adding -std=c++11 at my CmakeLists.txt as below:

    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall  -O3 -march=native -std=c++11")
    
    0 讨论(0)
  • 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 <mutex> 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).

    0 讨论(0)
  • 2020-11-28 14:05

    I installed Cygwin instead of WinGW. instructions on youtube https://www.youtube.com/watch?v=DAlS4hF_PbY&t=245s

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