Question

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!

Was it helpful?

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.

OTHER TIPS

From https://scons.org/doc/2.3.4/HTML/scons-man.html

"scons does not automatically propagate the external environment used to execute scons to the commands used to build target files. This is so that builds will be guaranteed repeatable regardless of the environment variables set at the time scons is invoked. This also means that if the compiler or other commands that you want to use to build your target files are not in standard system locations, scons will not find them unless you explicitly set the PATH to include those locations. Whenever you create an scons construction environment, you can propagate the value of PATH from your external environment as follows:" ...

"import os env = Environment(ENV = os.environ)"

I found that when using scons and scl devtoolset that the initial scons script would use the proper g++/gcc version but any dependent scons scripts would use the default one not the current devtoolset. Making the above change to the environment fixed that issue.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top