0

In my Ubuntu Netbeans 7.3 installation, I have a C++ project with C++11 marked as the standard in the C++ Compiler Options. When I try to include <chrono> it does not seem to make the std::chrono namespace available. When I open up this file to see what's wrong, I see everything greyed out but his first section:

#ifndef _GLIBCXX_CHRONO
#define _GLIBCXX_CHRONO 1

#pragma GCC system_header

#if __cplusplus < 201103L
# include <bits/c++0x_warning.h>
#else

When I hover over the __cplusplus constant, to see how it was defined, it says it's defined as 199711L. Why is this? I clearly set the project C++ Standard to C++11.

Jeroen
  • 15,257
  • 12
  • 59
  • 102
  • What compiler are you using? I'm working on Arch Linux with GCC4.8.1, netbeans, and `std::chrono` works perfectly fine. Could be an error in your compiler installation – Manu343726 Oct 03 '13 at 18:46
  • @Manu343726 GCC 4.8.1 also on a Linux distro. Same as you it seems. I've also noticed Netbeans is having trouble parsing extended classes inside header files. – Jeroen Oct 03 '13 at 19:08
  • @Manu343726 That header bug seems to be unrelated to this issue though. – Jeroen Oct 03 '13 at 19:19
  • Be patient. If the project is large, netbeans could need a couple of minutes to parse all he files. Also that could lead in bad preprocessing (Netbeans preprocessing says code enclosed with `#if#endif` will be not generated (Note the gray layout) for example), but when you build the project you see that the code is correctly preprocessed. – Manu343726 Oct 03 '13 at 19:32
  • @Manu343726 The project is small, and when I click reparse project in the code assist menu by right clicking on my project, it can completely finish and still have this bug. – Jeroen Oct 03 '13 at 19:49
  • For `g++` to define `__cplusplus` as `201103L`, you need to invoke it with `-std=c++11` or `-std=gnu++11` (the latter enables GNU-specific extensions). Which means you need to figure out how to get NetBeans to invoke g++ with that option. I don't know how to do that (which is why this is a comment rather than an answer). – Keith Thompson Jun 07 '14 at 18:43

1 Answers1

2
  1. Go to Tools->Options
  2. Select C/C++ menu
  3. Select Code Assistance tab
  4. Select C++ Compiler tab
  5. In Macro Definitions list view, locate __cplusplus and change its value to 201103L
  6. Click OK button
eigil
  • 96
  • 4
  • 2
    That's almost certainly a bad idea. The `__cplusplus` macro is defined by the compiler to indicate which version of the standard it supports. Changing it yourself is like trying to make your car go faster by pushing the needle on the speedometer to the right. – Keith Thompson Jun 07 '14 at 18:38
  • 1
    In this case I know that the speedometer is wrong; Notice it's for the Code Assistance only! The code compiles just fine without the correction. If I print the macro, it shows 201103L as expected. – eigil Jun 08 '14 at 10:31
  • I don't think so. The compiler chooses, based on command-line arguments, which version of the standard to support. `-std=c++11` causes it to (a) support C++11-specific features, and (b) define `__cplusplus` as `201103L`. Just changing the definition of `__cplusplus` won't cause the compiler to support C++11-specific features. (Unless NetBeans has some special handling for `__cplusplus`, which would be an odd way to do things.) – Keith Thompson Jun 08 '14 at 21:22
  • For example, a program that depends on a C++-specific feature (like `auto x = 42;`) will not compile even with `g++ -std=c++98 -D__cplusplus=201103L`. I presume changing the value of `__cplusplus` to `201103L` in NetBeans is equivalent to using `-D__cplusplus=201103L`, *not* to using `-std=c++11`. – Keith Thompson Jun 08 '14 at 21:45
  • But perhaps I'm missing something. "Code assistance" is separate from the compiler, right? Setting the option for C++11 *should* tell the code assistant to set `__cplusplus` to `201103L`. Is this a bug in NetBeans, and your suggestion a workaround for that bug? See also [this question](http://stackoverflow.com/q/14867428/827263/). – Keith Thompson Jun 08 '14 at 21:53
  • Yes, that is what I did :-) – eigil Jun 15 '14 at 09:27