改进办法:
cmake_minimum_required(VERSION 3.5) project(timer2) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
#包含自己编译的boost库 set(Boost_INCLUDE_DIR /home/your/dir/CPP/boost_1_61_0) set(Boost_LIBRARY_DIR /your/dir/boost_1_61_0/stage/lib) set(BOOST_ROOT "/home/andy/Linux/CPP/boost_1_61_0") find_package(Boost REQUIRED system) link_directories(${Boost_LIBRARY_DIR}) set(SOURCE_FILES main.cpp) add_executable(timer2 ${SOURCE_FILES})
#链接该boost库
target_link_libraries(timer2 ${Boost_LIBRARIES})
#添加
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -lboost_system")
add_definitions(${CMAKE_CXX_FLAGS})
参考:
http://stackoverflow.com/questions/20870249/undefined-reference-errors-when-linking-to-boost-using-cmake