CMake with SDL 2.0 and C ++ 11

I'm having trouble compiling C ++ 11 / SDL 2.0 code using CMake. CMakeLists is pretty simple:

cmake_minimum_required(VERSION 2.6)
project(Test)

include(FindPkgConfig)
pkg_search_module(SDL2 REQUIRED sdl2)
include_directories(${SDL2_INCLUDE_DIRS})
target_link_libraries(sdl2test ${SDL2_LIBRARIES})

add_definitions(-std=c++0x)
add_executable(Test src/main.cpp)

However, when compiling, I get this error:

Scanning dependencies of target Test
[100%] Building CXX object CMakeFiles/Test.dir/src/main.cpp.o
/var/dev/cmake/src/main.cpp: In function β€˜int main(int, char**)’:
/var/dev/cmake/src/main.cpp:11:16: error: β€˜nullptr’ was not declared in this scope
/var/dev/cmake/src/main.cpp:17:16: error: β€˜nullptr’ was not declared in this scope
make[2]: *** [CMakeFiles/Test.dir/src/main.cpp.o] Error 1
make[1]: *** [CMakeFiles/Test.dir/all] Error 2
make: *** [all] Error 2

cmake version 2.8.9 and gcc 4.7.2. Any ideas on how to properly use the features of C ++ 11 with CMake?

ps: I also tried -std = C ++ 11

+4
source share
1 answer

add_definitionsreally intended to define preprocessor definitions. You need to install CMAKE_CXX_FLAGShere:

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
+3
source

All Articles