1

I am trying to use the library Armadillo in my C++ code. When I try to use it, it gives me an error: "error: 'mutex' in namespace 'std' does not name a type"

I get the same error with the following minimalist implementation:

#include <iostream>
#include <mutex>
std::mutex mtx;
int main () {

  return 0;
}

I think the "mutex" library is simply not there. I am using Windows, G++ 8.1.0, MinGW-w64, and SublimeText for editing. I am adding -std=c++11 when running the file. I run the file using the following command (try_mutex.cpp is a file with the previous code):

g++ -std=c++11 try_mutex.cpp

The output is as follows:

try_mutex.cpp:3:6: error: 'mutex' in namespace 'std' does not name a type
 std::mutex mtx;
      ^~~~~
try_mutex.cpp:3:1: note: 'std::mutex' is defined in header '<mutex>'; did you forget to '#include <mutex>'?
+#include <mutex>
 std::mutex mtx;
 ^~~
bla2281
  • 31
  • 3
  • 2
    What version of GCC? Are you compiling with C++11 or greater enabled? – Collin May 08 '20 at 17:41
  • Besides what is already said. Are you sure that this is the only thing gcc shows as error? Because it should also show you and additional error that is something like `#error This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options.` or `#error This file requires compiler and library support for the ISO C++ 2011 standard. This support must be enabled with the -std=c++11 or -std=gnu++11 compiler options.` – t.niese May 08 '20 at 17:47
  • I am using -std=c++11 when running the file from the command line. I don't get the error that you are mentioning – bla2281 May 08 '20 at 18:00
  • Please show your compiler command line and full compiler output – Alan Birtles May 08 '20 at 18:00
  • I added the command line and output @AlanBirtles – bla2281 May 08 '20 at 18:06
  • What is the *first* error you're getting from your compiler? Certainly this isn't the only error. You also say you're using library Armadilla, but I don't see that in your example at all? Please make sure the example you provide actually reproduces the error. – JohnFilleau May 08 '20 at 18:07
  • Last time I checked, there's not a GNU implementation for windows threads. I'm not on Windows, but I have setup mingw64 to cross-compile from a linux system. – Stephen Newell May 08 '20 at 18:07
  • Same issue, but for an older version of mingw64 - https://stackoverflow.com/questions/14191566/c-mutex-in-namespace-std-does-not-name-a-type – Stephen Newell May 08 '20 at 18:10

0 Answers0