cmake中使用c++11

本文介绍了如何通过CMake配置项目以使用C++11标准,并展示了如何在Windows环境下使用mingw编译器设置CMakeLists.txt来链接Boost库。此外,还提供了具体的配置示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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} )

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值