如何告诉SCONS使用C 11标准

How to tell scons to use the C++11 standard

本文关键字:标准 使用 何告诉 SCONS      更新时间:2023-10-16

我没有设法找到如何告诉SCONS接受C 11标准:

sconstruct File:

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

我不确定在SCONS中是否支持SCONS_CXX_STANDARD

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

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

如这个问题所述,您可能需要-gnu++11