3

On a Red Hat Linux station, I use the devtoolset2 giving the following command:

scl enable devtoolset-2 bash

Then, when I call gcc --version, I get :

gcc (GCC) 4.8.2 20140120 (Red Hat 4.8.2-15) Copyright (C) 2013 Free Software Foundation, Inc.

But if I compile my program (malkefile generated with cmake, adding the line :

if(UNIX)
    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -std=c++11")
endif()

I have the following error message :

cc1plus: error: unrecognized command line option "-std=c++11"

And if I compile replacing -std=c++11 by -std=c++0x then, I obtain these messages :

nullptr wasnt declared in this scope.

How nullptr cannot be recognized considering it is a keyword ?

I don't understand, if you have any idea...

Moe
  • 28,607
  • 10
  • 51
  • 67
Quentin Tealrod
  • 309
  • 3
  • 14
  • 1
    according to [this](https://gcc.gnu.org/projects/cxx0x.html) `nullptr` was supported since version 4.6 – NathanOliver Aug 26 '15 at 15:23
  • 2
    `cc1plus: error: unrecognized command line option "-std=c++11"` <-- cc1plus isn't g++ – C0deH4cker Aug 26 '15 at 15:24
  • 1
    Are you sure cmake is using the correct gcc version? – interjay Aug 26 '15 at 15:28
  • 2
    @C0deH4cker cc1plus is the compiler part of g++. – interjay Aug 26 '15 at 15:34
  • 1
    @interjay Correct. However, only the g++ compiler frontend specifically understands the `--std=c++11` flag. It converts that into arguments understood by cc1plus. – C0deH4cker Aug 26 '15 at 15:36
  • What command exactly is cmake using to invoke g++? If you're using the make backend, you may need to try something like `make V=1` to see the commands. – ex-bart Aug 26 '15 at 15:37
  • @C0deH4cker: Is it not suspicious that it accepted `-std=c++0x`? I think you're wrong. I suspect the problem is that a _much_ older GCC than 4.8.2 is being invoked from CMake ([`nullptr` wasn't added until 4.6](http://stackoverflow.com/a/3756481/560648)) – Lightness Races in Orbit Aug 26 '15 at 15:38
  • 2
    @C0deH4cker That isn't my experience: `$ g++ q.cpp -std=asdf` results in: `cc1plus: error: unrecognized command line option "-std=asdf"` – interjay Aug 26 '15 at 15:39
  • 1
    Speculation: this might be an issue with the cmake cache, if you initially invoked cmake in a different environment (i.e. before you did `scl enable devtoolset-2 bash`) – ex-bart Aug 26 '15 at 15:40
  • 1
    @LightnessRacesinOrbit Oops, you are correct. I made a false assertion without first checking if I was correct. – C0deH4cker Aug 27 '15 at 03:07

1 Answers1

5

You are not invoking GCC 4.8.2.

Either there is something wrong with your CMake configuration, or there is something wrong with your SCL invocation, or gcc -v gives a different answer to g++ -v (in which case, check the contents of your toolset).

But nullptr not being available, and -std=c++0x being accepted but not -std=c++11, all suggest GCC 4.3, 4.4 or 4.5.

One thing you can try is to remove the file CMakeCache.txt from your build root, which may contain cached properties of your previous environment.

Failing that, turn on verbose output so you can really see what's going on, what binaries are being invoked, and how.

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
  • Thanks a lot for your answer. remve the cmake cache doesn't change anything. I tried to set CMAKE_COMPILER_IS_GNUCXX to true in order to make g++ run but unsuccessfully. – Quentin Tealrod Aug 28 '15 at 12:32
  • I tried to run verbose, setting CMAKE_VERBOSE_MAKEFILE to ON, but it doesn't seem to work. Do you know exactly how we do that ? Thanks – Quentin Tealrod Aug 28 '15 at 13:06
  • I also need to add that in the generated Makefile, it's written VERBOSE = 1, but in the CMakeCache.txt I have : CMAKE_VERBOSE_MAKEFILE:BOOL=OFF and no more information about the compiler or smtg related... – Quentin Tealrod Aug 28 '15 at 13:18