c++11 - 使用 scons 编译带有 -std=c++11 标志的 c++ 文件

标签 c++11 scons

我正在尝试使用 scons 编译带有 -std=c=+11 选项的 c++ 文件。

文件:test.cc

#include <unordered_map>

int foo()
{ return 0; }

文件:SConstruct

env = Environment()
env.Append(CXXFLAGS = '-std=c++11')
#print env['CXXFLAGS']

src_files = Split('test.cc')
lib_name = 'test'

Library(lib_name, src_files)

我收到以下错误。调用 g++ 时,CXXFLAGS 似乎没有生效:

g++ -o test.o -c test.cc
In file included from /usr/include/c++/4.8.2/unordered_map:35:0,
                 from test.cc:2:
/usr/include/c++/4.8.2/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
 #error This file requires compiler and library support for the \
  ^
scons: *** [test.o] Error 1

我已经阅读了一些关于通过修改“构造环境”来使用-std=c++11 选项编译c++ 文件的帖子,我觉得我已经做到了。有人可以帮忙吗。

谢谢, 艾哈迈德。

最佳答案

使用 env.Library 而不是 Library 来构建带有您的构建环境的库。

env = Environment()
env.Append(CXXFLAGS = '-std=c++11')

src_files = Split('test.cc')
lib_name = 'test'

env.Library(lib_name, src_files)

关于c++11 - 使用 scons 编译带有 -std=c++11 标志的 c++ 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31232955/

相关文章:

c++ - 使用 SDL 2.0 和 C++11 的 CMake

c++ - 在虚析构函数中调用其他虚方法是否安全?

c++ - 如何让项目将其构建输出与 Scons 放在同一目录中?

scons - scons是否知道SConscript文件位于哪个目录中?

c++ - Scons 重新编译我的代码

c - 强制 scons 中出现 "undefined symbol"编译时错误

c++ - 如何检查类型是否提供具有算术类型的函数

c++ - 强制C++类具有对齐的属性

c++父类(super class)为子类定义静态成员变量

file - 如何为 scons 指定一个目录来存储所有 .o(中间) 文件?