2012-11-01 16 views
6

nie udało się znaleźć sposób, aby powiedzieć scons przyjąć C11 standardu ++Jak powiedzieć scons używać standardowej C++ 11

plik SConstruct:

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

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

plik cpp:

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

komunikat o błędzie podczas wywoływania 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. 

oczywiście nie rozumie auto i nullptr

Odpowiedz

11

Nie jestem pewien, czy SCONS_CXX_STANDARD jest jeszcze obsługiwana w SCons.

Zamiast tego, jeśli używasz GCC 4.7 lub nowszy, spróbuj przechodząc -std=c++11 do kompilatora następująco:

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

Jak wyjaśniono w this question, być może trzeba -gnu++11

+1

Tak thanx. Działa dobrze, ale poprawiłem twoją odpowiedź: prawdziwą flagą g ++ jest -std = C++ 0x, nie -std = C++ 11 –

+0

@StephaneRolland, ok dzięki – Brady

+0

Tak, scons nie jest kompilatorem i nie obsługuje instrukcji takich jak CXX_STANDART . To tylko flaga kompilatora. – Torsten