7

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

Stephane Rolland
  • 38,876
  • 35
  • 121
  • 169

1 Answers1

13

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

Community
  • 1
  • 1
Brady
  • 10,207
  • 2
  • 20
  • 59
  • 1
    yep thanx. It works fine, but I corrected your answer: the real g++ flag is -std=c++0x, not -std=c++11 – Stephane Rolland Nov 01 '12 at 14:48
  • Yes, scons is not compiler and dont support instruction like CXX_STANDART. It's just compiler flag. – Torsten Nov 01 '12 at 18:21
  • 4
    @StephaneRolland : That's only true through GCC 4.6.x – starting with GCC 4.7, it is indeed supposed to be `-std=c++11`. – ildjarn Nov 01 '12 at 19:42
  • 2
    This answer is incorrect now, current versions of SCons support `SCONS_CXX_STANDARD`. – mdd Mar 04 '19 at 16:52
  • @mdd where in the SCons documentation did you find this? – Nate Glenn Dec 12 '22 at 19:28
  • @NateGlenn I can confirm the SCons codebase (and docs) have no reference to this as of the end of 2022 (when you added this comment). Suspecting some project defined it for themselves (it's not a terrible idea, but hasn't been proposed to the SCons project that I can tell) – Mats Wichmann Dec 12 '22 at 20:44
  • You're right, it might have been some project-specific setting. – mdd Dec 13 '22 at 20:03