Using scons to compile c++ file with -std=c++11 flag

匿名 (未验证) 提交于 2019-12-03 01:00:01

问题:

I am trying to compile a c++ file with -std=c=+11 option using scons.

File : test.cc

#include <unordered_map>  int foo() { return 0; } 

File : 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) 

I am getting the following error. It seems CXXFLAGS is not taking effect when g++ is invoked:

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 

I have read a few postings about compiling c++ files with -std=c++11 option by modifying the "Construction Environment", which I feel I have done. Can someone please help.

Thank you, Ahmed.

回答1:

Use env.Library instead of Library to build the library with your construction environment.

env = Environment() env.Append(CXXFLAGS = '-std=c++11')  src_files = Split('test.cc') lib_name = 'test'  env.Library(lib_name, src_files) 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!