cmake中使用c++11

CMakeLists.txt文件如下:

"add_compile_options(-std=c++11)"是关键


cmake_minimum_required (VERSION 2.6)

project (hello)
SET(CMAKE_C_COMPILER g++)
add_compile_options(-std=c++11)
set(SRC_LIST test.c)

add_executable(hello ${SRC_LIST})



另外,cmake中引用用boost线程的demo如下(windows上的mingw):

cmake_minimum_required (VERSION 2.6)
PROJECT(demo)
SET(SRC_LIST main.cpp)
set(BOOST_ROOT "D:/boost/boost_1_60_0/boost_1_60_0")
set(Boost_DIR D:/boost/boost_1_60_0/boost_1_60_0)

find_package(Boost 1.60.0 REQUIRED)
find_package (Threads)  
find_package(Boost COMPONENTS system filesystem thread log program_options REQUIRED) 


if(NOT Boost_FOUND)
  message(FATAL_ERROR "Could not find boost!")
endif()


SET(CMAKE_C_COMPILER g++)
SET(CMAK_CXX_COMPILER g++)
add_compile_options(-std=c++11)


INCLUDE_DIRECTORIES("D:/boost/boost_1_60_0/boost_1_60_0")  
LINK_DIRECTORIES("D:/boost/boost_1_60_0/boost_1_60_0/stage/lib") 
ADD_EXECUTABLE(hello ${SRC_LIST})
target_link_libraries(hello ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES} )

你可能感兴趣的:(c++)