简体   繁体   English

Scons选择哪个g ++版本| 无法识别的命令行选项“ -std = c ++ 11”

[英]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: 在OpenSUSE中使用Scons 2.3.0时遇到问题:

When I added "-std=c++11" option, I saw the error 当我添加“ -std = c ++ 11”选项时,我看到了错误

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

I realized that it is because my g++ version was too old (4.1). 我意识到这是因为我的g ++版本太旧(4.1)。 So I upgraded it to 4.7.1. 所以我将其升级到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) 我将g ++ 4.7.1的路径移至$ PATH中的第一位(在/ usr / bin之前)
  2. when I try 当我尝试

      which g++ 

    I saw it shows the path to my new g++4.7.1 我看到它显示了通往新g ++ 4.7.1的路径

  3. when I try g++ -v I also saw the version 4.7.1 当我尝试g++ -v我也看到了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. 如果不尝试使用scons,则如果我尝试使用g++ -std=c++11 helloWorld.cpp构建一个简单的g++ -std=c++11 helloWorld.cpp ,则一切正常。

  5. Now by using scons, I saw the cc1plus: error: unrecognized command line option "-std=c++11" 现在,通过使用scons,我看到了cc1plus 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) 我什s.system("g++ -v")在我的SConstruct文件中添加了s.system("g++ -v") ,它仍然可以打印正确的版本(4.7.1)

So I am not sure which part I did wrong. 所以我不确定哪一部分做错了。

Please give me some advice 请给我一些建议

Thanks in advance for the help! 先谢谢您的帮助!

SCons is choosing the older version of the compiler be default. SCons选择默认版本的编译器作为默认版本。

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. 进行os.system("g++ -v")将使用您的PATH,但是SCons在内部不使用PATH查找编译器,而是在标准位置中查找。

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 . 您可以在此处找到所有构造变量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM