3

Simple program like this

#include <iostream>       // std::cout
#include <thread>         // std::thread
#include <mutex>          // std::mutex

std::mutex mtx;           // mutex for critical section

int main ()
{
     return 0;
}

Tried the following to compile

$ /usr/local/Cellar/gcc46/4.6.4/bin/g++-4.6 -std=gnu++0x -I/usr/local/Cellar/gcc46/4.6.4/gcc/include/c++ -L/usr/local/Cellar/gcc46/4.6.4/gcc/lib temp_mutex.cpp 
temp_mutex.cpp:6:1: error: 'mutex' in namespace 'std' does not name a type

By the way I am compiling on Mac.

rkb
  • 10,933
  • 22
  • 76
  • 103
  • 1
    check [this](http://stackoverflow.com/questions/14191566/c-mutex-in-namespace-std-does-not-name-a-type),maybe help – ningyuwhut Aug 21 '13 at 02:08
  • Hmm, [this person](http://stackoverflow.com/q/10308167/13) successfully used `std::mutex` on gcc 4.7 on their Mac. Try that. :-D – C. K. Young Aug 21 '13 at 02:41
  • I tried it but no luck. – rkb Aug 21 '13 at 03:03
  • Try updating your GCC. You can download and compile the latest version from source from the GCC website. (Or just install XCode, that comes with the GCC command line tools by itself.) – Appleshell Aug 21 '13 at 03:34
  • 1
    The answers to the "duplicate" question are about problems with mingw on windows. The OP says he is using g++ on a Mac. – markgz Mar 26 '15 at 19:51

1 Answers1

5

It worked for me:

$ g++-4.7 -O2 -Wall -std=c++11 -c mutextest.cc
$ g++-4.6 -O2 -Wall -std=c++0x -c mutextest.cc
$ g++-4.6 -O2 -Wall -std=gnu++0x -c mutextest.cc
$ g++-4.4 -O2 -Wall -std=c++0x -c mutextest.cc
$ g++-4.4 -O2 -Wall -std=gnu++0x -c mutextest.cc

None of these generated any error messages.

C. K. Young
  • 219,335
  • 46
  • 382
  • 435
  • 4
    How many versions of gcc do you have? :) – billz Aug 21 '13 at 02:21
  • @billz Just those 3. My system started out with [Squeeze](http://www.debian.org/releases/squeeze/), but was recently upgraded to [Wheezy](http://www.debian.org/releases/wheezy/). I guess the upgrade retained the older versions. – C. K. Young Aug 21 '13 at 02:23
  • Am I missing anything in particular. Because I tried the exact same things and I still get this error which makes me feel like I am missing something to include or link for the same.\ – rkb Aug 21 '13 at 02:35