Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c++11

scons

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.

like image 477
Ahmed A Avatar asked Nov 17 '25 08:11

Ahmed A


1 Answers

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)
like image 147
Dave Bacher Avatar answered Nov 20 '25 04:11

Dave Bacher



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!