Search code examples
c++gccc++11sconsg++-4.7

which version of g++ does Scons pick | unrecognized command line option "-std=c++11"


I am experiencing a problem when using Scons 2.3.0 in OpenSUSE:

When I added "-std=c++11" option, I saw the error

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

I realized that it is because my g++ version was too old (4.1). So I upgraded it to 4.7.1. The follow thing are also done

  1. I had the path of the g++4.7.1 moved to the first place in $PATH (before /usr/bin)
  2. when I try

      which g++
    

    I saw it shows the path to my new g++4.7.1

  3. when I try g++ -v I also saw the version 4.7.1

  4. WITHOUT using scons, if I try to build a simple helloWorld with g++ -std=c++11 helloWorld.cpp, everything works fine.

  5. Now by using scons, I saw the cc1plus: error: unrecognized command line option "-std=c++11"

  6. I even added s.system("g++ -v") in my SConstruct file, it still prints the right version (4.7.1)

So I am not sure which part I did wrong.

Please give me some advice

Thanks in advance for the help!


Solution

  • SCons is choosing the older version of the compiler be default.

    Doing os.system("g++ -v") will use your PATH, but SCons internally doesnt use the PATH to find the compiler, it looks in standard locations.

    If you cant uninstall the old version of the compiler, you may have to explicitly point out the new compiler. This can be done by setting some Construction Variables on the Environment as follows:

    env = Environment()
    env.Replace(CXX='path/g++')
    env.Replace(CC='path/gcc')
    

    You can find all the construction variables here.