Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c++

c++11

scons

I don't manage to find how to tell scons to accept c++11 standard:

the SConstruct file:

env=Environment(CPPPATH='/usr/include/boost/',
                CPPDEFINES=[],
                LIBS=[],
                SCONS_CXX_STANDARD="c++11"
                )

env.Program('Hello', Glob('src/*.cpp'))

the cpp file:

#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;
};

error message when calling 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.

obviously it doesn't understand auto and nullptr

like image 513
Stephane Rolland Avatar asked Nov 01 '12 14:11

Stephane Rolland


People also ask

What compiler does SCons use?

The Visual C++ compiler option that SCons uses by default to generate PDB information is /Z7 . This works correctly with parallel ( -j ) builds because it embeds the debug information in the intermediate object files, as opposed to sharing a single PDB file between multiple object files.

How does SCons work?

SCons is a computer software build tool that automatically analyzes source code file dependencies and operating system adaptation requirements from a software project description and generates final binary executables for installation on the target operating system platform.

How can I speed up my SCons?

The command 'scons --max-drift=1 --implicit-deps-unchanged' will execute your build as fast as possible.

Does SCons generate Makefile?

Tools integrating with SCons It is used to control the software compilation process using simple platform and compiler independent configuration files, and generate native makefiles and workspaces that can be used in the compiler environment of the user's choice.


1 Answers

Im not sure if SCONS_CXX_STANDARD is supported yet in SCons.

Instead, if you're using GCC 4.7 or later, try passing -std=c++11 to the compiler as follows:

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

As explained in this question, you may need -gnu++11

like image 163
Brady Avatar answered Oct 09 '22 10:10

Brady