Cmake找不到boost库

时间:2015-08-16 17:49:56

标签: c++ c++11 boost cmake

我在Mac OS X上使用以下CMake文件,在/ usr / local / lib / boost_1_58_0安装了Boost v1.58.0,每次运行cmake时都会打印"无法找到升压&#34 ;.我已经阅读了关于如何使其工作的每个堆栈溢出帖子,并没有任何工作。我有什么遗失的吗?

cmake_minimum_required (VERSION 3.1)
project (HelloWorld)

set (CMAKE_CXX_FLAGS "--std=gnu++11 ${CMAKE_C_FLAGS}")
file (GLOB SOURCE_FILES "source/*.cpp")

set (CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} /usr/local/lib/boost_1_58_0/boost)
set (CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} /usr/local/lib/boost_1_58_0/stage/lib)

set (Boost_NO_BOOST_CMAKE ON)   
set (BOOST_NO_SYSTEM_PATHS ON)
set (BOOST_ROOT /usr/local/lib/boost_1_58_0)
set (BOOST_INCLUDEDIR /usr/local/lib/boost_1_58_0/boost)
set (BOOST_LIBRARYDIR /usr/local/lib/boost_1_58_0/stage/lib)

set (Boost_USE_STATIC_LIBS OFF)
set (Boost_USE_MULTITHREADED ON)
set (Boost_USE_STATIC_RUNTIME OFF)
find_package (Boost 1.58.0 COMPONENTS optional)

if (Boost_FOUND)
    include_directories (${Boost_INCLUDE_DIRS})
    target_link_libraries (helloworld ${Boost_LIBRARIES})
endif ()

include_directories ("source")
add_executable (helloworld ${SOURCE_FILES})

1 个答案:

答案 0 :(得分:2)

这是破坏因为可选项不是库,它只是标题,所以将其更改为find_package (Boost 1.58.0)可以解决问题。