0

My code is compiled using the g++ compiler version 4.9.0. I'm using C++11.

However, the compiler doesn't understand the nullptr keyword. Here is what I've found out:

  1. This is not a typo, because the word nullptr is displayed in bold in the editor.
  2. g++ supports nullptr, because its version is greater than 4.6.0.
  3. The compiler understands that I want to use C++11, because it doesn't complain when I use auto or decltype one line earlier (I use the -std=c++0x command-line argument, but I also the -std=gnu++0x).

I have no idea what else can be wrong, so I'll be grateful for any suggestions.

Edit: the error message is the following:

error: nullptr was not declared in this scope.

This is the output of the g-- version command:

g++ (OSE 4.9.2-2 20160202) 4.9.2
user2738748
  • 1,106
  • 2
  • 19
  • 36

2 Answers2

1

The flag in recent versions of g++ is -std=c++11.

J.N.
  • 8,203
  • 3
  • 29
  • 39
  • I tried using this flag, but it wasn''t recognised by my compiler. – user2738748 Apr 07 '16 at 12:52
  • @user2738748 g++ 4.9.0 does understand this flag. What's the output of `g++ --version`? – jotik Apr 07 '16 at 12:58
  • @jotik, I know it does. This is why I am surprised. – user2738748 Apr 07 '16 at 13:22
  • @J.N. `-std=c++0x` still works though, and means exactly the same thing. So this is not an answer, and should maybe be a comment. – Jonathan Wakely Apr 07 '16 at 13:24
  • However, it might be useful to try compiling with `-std=c++11` because it would fail and confirm the OP is not using a recent version! – Jonathan Wakely Apr 07 '16 at 13:31
  • @JonathanWakely, I did confirm that it fails (see my first comment to this answer). So probably I'm not using a recent version of the g++ compiler. But I printed out the version of the g++ compiler and it was 4.9.2. – user2738748 Apr 07 '16 at 15:15
  • Which means that when you compile it isn't using that same `g++`. C'mon, this is obvious. If running `g++` at the shell finds 4.9.2 but running `make` uses a compiler that isn't 4.9.2, then `make` is finding a different compiler. And we can't help you figure that out because you can't show us the makefile and we don't have access to your compilation environment. Maybe find a colleague who understands the setup and ask them how it works. "Why does my company have several different compilers installed in different paths and how do I use them?" is not a suitable question for stackoverflow. – Jonathan Wakely Apr 08 '16 at 09:53
-1

My code is compiled using the g++ compiler version 4.9.0. I'm using C++11.

No it isn't, it's being compiled with GCC 4.5, or older. Otherwise nullptr would work.

This is the output of the g-- version command:

g++ (OSE 4.9.2-2 20160202) 4.9.2

Well that's certainly not 4.9.0, what is OSE?

How are you compiling your code? Because it seems to be finding a different version of GCC, not that one.

Community
  • 1
  • 1
Jonathan Wakely
  • 166,810
  • 27
  • 341
  • 521
  • OSE stands for Open Source Edition. It's 4.9.2, but it's newer than 4.9.0, so it doesn't change anything. I can't copy my makefile here, because it belongs to my company. I'm using the following flags: -c -g -Wall. I also pass my own "flag" which is used as a directive in the code. – user2738748 Apr 07 '16 at 13:35
  • Check the PATH being used by the makefile. You could also add `-v` to the flags, which will tell you lots of info about the GCC version. Running `g++ --version` on the command line doesn't necessarily find the same `g++` as the makefile finds. – Jonathan Wakely Apr 07 '16 at 13:36
  • I added the -v option and it turned out that I'm using the following version of the gcc compiler: gcc version 4.4.6 (crosstool-NG 1.12.1). Part of the code is compiled using the gcc compiler and part using the g++ compiler. I didn't get any information about the version of the g++ compiler. Do you mean the PATH environmental variable? – user2738748 Apr 07 '16 at 14:20
  • Yes, I meant the PATH environment variable, since that's what determines where `make` finds the compiler, but you have your answer now. You're using GCC 4.4.6, not 4.9, as I said. – Jonathan Wakely Apr 07 '16 at 14:30
  • I'm using the gcc compiler to compile the part of my code that doesn't require objectivity. I'm also using g++ to compile all the classes (with nullptr and C++11). I can see that in the compiler output. It looks like that: powerpc-unknown-linux-gnu-g++ . But then I don't understand why I wasn't able to read out the version of the g++ compiler with the *-v* option. Regarding the PATH variable, this is the only part of it which has anything to do with the compiler: *i686-pc-linux-gnu/bin*. – user2738748 Apr 07 '16 at 15:06
  • 1
    I think you're confused about how "objectivity" and compiling C++ works, using `gcc` to compile doesn't mean you can't use C++ features. If you're compiling with `powerpc-unknown-linux-gnu-g++` then you need to run `powerpc-unknown-linux-gnu-g++ --version` to find the version, not `g++ --version` which runs a completely different program on your system. – Jonathan Wakely Apr 07 '16 at 16:24
  • In the makefile I can see that I'm using the gcc compiler to compile some signals and that I'm using the g++ compiler to compile the rest of the code. I ran *powerpc-unknown-linux-gnu-g++ --version*, but this command wasn't recognized by the shell, so I used the absolute path and I got *access denied* error. I checked that I can use gcc to compile C++ code. It was surprising, but I'm aware of that now. I'm sure I'm compiling the clases that have nullptr with the g++ compiler- this is what I see during compilation. – user2738748 Apr 08 '16 at 09:12
  • Well **clearly you're not** using GCC 4.9, or it would work. I can't tell you what's wrong with your environment, because I don't have access to it. You need to understand and/or fix your makefiles if you think it should be compiling with 4.9, because it isn't. – Jonathan Wakely Apr 08 '16 at 09:50