1

I updated my g++ because my older version didn't fully support std::filesystem, but now I cannot use mutexes at all. Example code:

#include <mutex>

int main(const int argc, const char** argv)
{
  std::mutex test;
  return 0;
}

Compiled with:

g++ -Wall -pedantic main.cpp -std=c++17 -o main.exe

The error, note how it suggests adding include for <mutex> right under the include that is already there:

main.cpp: In function 'int main(int, const char**)':
main.cpp:5:8: error: 'mutex' is not a member of 'std'
    5 |   std::mutex test;
      |        ^~~~~
main.cpp:2:1: note: 'std::mutex' is defined in header '<mutex>'; did you forget to '#include <mutex>'?
    1 | #include <mutex>
  +++ |+#include <mutex>
    2 |

The full version of g++ is: g++ (MinGW.org GCC Build-2) 9.2.0. I installed MinGW using the MinGW installation manager. Is it possible that I am missing the correct version of stdlib?

I opened the mutex file in the MinGW directory and I see nothing that would be obviously wrong.

Tomáš Zato
  • 50,171
  • 52
  • 268
  • 778
  • Your code compiles fine with mingw installed using msys2 `g++.exe (Rev10, Built by MSYS2 project) 11.2.0` [https://www.msys2.org/](https://www.msys2.org/) – drescherjm Apr 20 '22 at 10:07
  • @drescherjm I guess I installed the wrong thing, even though I spent a decent time googling what should I install. – Tomáš Zato Apr 20 '22 at 10:12
  • I recommend using msys2. Not only do you get up to date mingw you have package management with pacman. Related: [https://stackoverflow.com/questions/30069830/how-to-install-mingw-w64-and-msys2](https://stackoverflow.com/questions/30069830/how-to-install-mingw-w64-and-msys2) – drescherjm Apr 20 '22 at 10:18
  • If you don't want all of MSYS2 you can also go for the standalone compiler from https://winlibs.com/ – Brecht Sanders Apr 20 '22 at 13:59

0 Answers0