c++ - 如何告诉 scons 使用 C++11 标准

标签 c++ c++11 scons

我没找到如何告诉 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

最佳答案

我不确定 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

关于c++ - 如何告诉 scons 使用 C++11 标准,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13179316/

相关文章:

c++ - 编译器何时应该生成 move 构造函数?

directory - 从层次结构中的上游目录运行 scons

c++ - 为我的应用程序第 2 部分保存用户数据

c++ - int min 的定点实现

c++ - 条件变量 "miss"可以通知调用吗?

python - 卸载安装有 `pip install --egg` 的 python 包

python - 如何使用 scons 构建任意食谱?

c++ - 为什么在这种情况下内存分配失败?

c++ - 使用 strncmp 函数在 Arduino IDE 中出错

c++ - 使用 Gtkmm 创建信号