您的位置:首页 > 编程语言 > C语言/C++

cmake中使用c++11

2016-04-28 19:03 357 查看
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} )
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: