VS2019 with clang++ v10 fails to compile code using std::mutex

Alec Miller 1 Reputation point
2021-03-21T01:11:21.197+00:00

We are noticing that builds using clang++ don't find std::mutex. Our app doesn't use any CLR, and is a pure C++ command line app/tool. What flags do we need to pass so that these important parts of std aren't blocked. I tried -pthread, but the default thread model is already posix according to the help.

Severity Code Description Project File Line Suppression State
Error GCCDED198 no type named 'mutex' in namespace 'std' Game C:\Foo.h 132
Error GCCDED198 no type named 'condition_variable' in namespace 'std'; did you mean 'OS::ConditionVariable'? Game C:\Foo.h 133
Error G61834E1F no template named 'unique_lock' in namespace 'std'; did you mean 'unique_copy'? Game C:\Foo.cpp 97
Error G1A4676F8 no member named 'wait' in 'OS::ConditionVariable' Game C:\Foo.cpp 130
Error G1A4676F8 no member named 'notify_one' in 'OS::ConditionVariable' Game C:\Foo.cpp 155
Error G1A4676F8 no member named 'notify_all' in 'OS::ConditionVariable' Game C:\Foo.cpp 104
Error G1A4676F8 no member named 'mutex' in namespace 'std' Game C:\Fooo.cpp 97

This is my setup

PS C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\Llvm\x64\bin> clang++ --version
clang version 10.0.0
Target: i686-pc-windows-msvc
Thread model: posix
InstalledDir: C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\Llvm\bin
PS C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\Llvm\x64\bin>

Developer technologies C++
{count} votes

1 answer

Sort by: Most helpful
  1. Alec Miller 1 Reputation point
    2021-03-21T05:53:08.533+00:00

    Thanks Igor,

    I was getting ready to try that next, but the code had compiled across 5 other platforms. That was the push I needed. #include <mutex> fixed the issue. I think our code had fallbacks to the native condition variables before Windows implemented that, and so it excluded the std include.

    Alec

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.