【问题标题】:How to tell scons to use the C++11 standard如何告诉 scons 使用 C++11 标准
【发布时间】:2012-10-22 04:08:39
【问题描述】:

我不知道如何告诉 scons 接受 c++11 标准:

SConstruct 文件:

env=Environment(CPPPATH='/usr/include/boost/',
                CPPDEFINES=[],
                LIBS=[],
                SCONS_CXX_STANDARD="c++11"
                )

env.Program('Hello', Glob('src/*.cpp'))

cpp 文件:

#include <iostream>
class A{};
int main()
{
  std::cout << "hello world!" << std::endl;
  auto test = new A; // testing auto C++11 keyword
  if( test == nullptr ){std::cout << "hey hey" << std::endl;} // testing nullptr keyword
  else{std::cout << " the pointer is not null" << std::endl;}
  return 0;
};

调用 scons 时的错误信息:

scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
g++ -o src/hello_world.o -c -I/usr/include/boost src/hello_world.cpp
src/hello_world.cpp: In function 'int main()':
src/hello_world.cpp:13:8: error: 'test' does not name a type
src/hello_world.cpp:15:7: error: 'test' was not declared in this scope
src/hello_world.cpp:15:15: error: 'nullptr' was not declared in this scope
scons: *** [src/hello_world.o] Error 1
scons: building terminated because of errors.

显然看不懂autonullptr

【问题讨论】:

    标签: c++ c++11 scons


    【解决方案1】:

    我不确定 SCons 是否支持 SCONS_CXX_STANDARD

    如果您使用的是 GCC 4.7 或更高版本,请尝试将 -std=c++11 传递给编译器,如下所示:

    env=Environment(CPPPATH='/usr/include/boost/',
                    CPPDEFINES=[],
                    LIBS=[],
                    CXXFLAGS="-std=c++0x"
                    )
    

    this question 中所述,您可能需要-gnu++11

    【讨论】:

    • 是的,谢谢。它工作正常,但我更正了你的答案:真正的 g++ 标志是 -std=c++0x,而不是 -std=c++11
    • 是的,scons 不是编译器,不支持像 CXX_STANDART 这样的指令。这只是编译器标志。
    • @StephaneRolland :这仅在 GCC 4.6.x 中是正确的——从 GCC 4.7 开始,它确实应该是 -std=c++11
    • 这个答案现在不正确,当前版本的 SCons 支持SCONS_CXX_STANDARD
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-05
    • 2023-03-18
    • 1970-01-01
    相关资源
    最近更新 更多