2

I have the following code:

#include <vector>
#include <string>
#include <mutex>
#include <queue>

std::mutex queue_mutex;
std::condition_variable condition;

int main(int argc, char** argv)
{
    return 0;
}

When compiling it on Windows, I have no problems, but once I do on Unix it does. I first tried compiling with: g++ -O3 -Wall tester.cpp -lpthread -o tester

But I get the following error:

In file included from /usr/include/c++/4.8/mutex:35:0,
                 from gamytester.cpp:7:
/usr/include/c++/4.8/bits/c++0x_warning.h:32:2: error: #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.
 #error This file requires compiler and library support for the \
  ^
gamytester.cpp:10:2: error: ‘mutex’ in namespace ‘std’ does not name a type
  std::mutex queue_mutex_;
  ^
gamytester.cpp:11:2: error: ‘condition_variable’ in namespace ‘std’ does not name a type
  std::condition_variable condition_;

So I tried to compile it using g++ -O3 -Wall -std=c++11 tester.cpp -lpthread -o tester

Which still lead me to another error:

gamytester.cpp:11:2: error: ‘condition_variable’ in namespace ‘std’ does not name a type
  std::condition_variable condition_;
  ^

I'm running openSUSE 13.02 and have the g++ compiler version 4.8.3.

Does anybody know how to help me?

Mdp11
  • 552
  • 4
  • 13
  • 5
    You need the `` header *aaand* `-std=c++11`... – StoryTeller - Unslander Monica Apr 02 '19 at 12:23
  • 2
    ... and you also need, perhaps, a newer version of gcc. That version of gcc is very old. gcc 8.3 would've given you exactly what the problem is: "`note: ‘std::condition_variable’ is defined in header ‘’; did you forget to ‘#include ’?`" – Sam Varshavchik Apr 02 '19 at 12:26
  • @StoryTeller perfect, that solved it! I didn't think about it because on Windows I did not have to include it, so I didn't even think about it. Thank you so much! – Mdp11 Apr 02 '19 at 12:29
  • @SamVarshavchik unfortunately I can't, since it's an university machine, not my own. But thank you anyway! – Mdp11 Apr 02 '19 at 12:29
  • 1
    Standard library headers may include each other. But one cannot rely on it. The only portable option is to write your required headers yourself. – StoryTeller - Unslander Monica Apr 02 '19 at 12:29

0 Answers0