我在使用 CMake 编译 C++11/SDL 2.0 代码时遇到了一些问题。CMakeLists 非常简单:
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)
但是,在编译时,我收到此错误:
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 版本 2.8.9 和 gcc 4.7.2。关于如何通过 CMake 正确使用 C++11 功能的任何想法?
ps:我也试过-std=c++11