CMake找不到Boost库 [英] CMake cannot find Boost libarary

查看:106
本文介绍了CMake找不到Boost库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Cmake的新手.我阅读了相同问题的帖子,但仍然无法解决我的问题.抱歉,同样的问题.

I'm new to Cmake. I read posts of the same problem but I still cannot solve my problem. Sorry about the same question.

我的增强包含在:/usr/local/Cellar/boost/1.58.0/include 我的boost库位于:/usr/local/Cellar/boost/1.58.0/lib

My boost include is in: /usr/local/Cellar/boost/1.58.0/include My boost lib is in: /usr/local/Cellar/boost/1.58.0/lib

我的CMakeLists.txt是:

My CMakeLists.txt is:

cmake_minimum_required(VERSION 2.6)
SET(BOOST_ROOT /usr/local/Cellar/boost/1.58.0)
SET(BOOST_INCLUDEDIR /usr/local/Cellar/boost/1.58.0/include)
SET(BOOST_LIBRARYDIR /usr/local/Cellar/boost/1.58.0/lib)
set(Boost_USE_STATIC_LIBS   ON)
find_package(Boost COMPONENTS optional REQUIRED)

include_directories(${Boost_INCLUDEDIR})
target_link_libraries(hash ${Boost_LIBRARYDIR})

我得到的调试消息是:

-- [ /usr/local/Cellar/cmake/3.4.1/share/cmake/Modules/FindBoost.cmake:551 ]     _boost_TEST_VERSIONS =   1.59.0;1.59;1.58.0;1.58;1.57.0;1.57;1.56.0;1.56;1.55.0;1.55;1.54.0;1.54;1.53.0;1.53;1.52.0;1.52;1.51.0;1.51;1.50.0;1.50;1.49.0;1.49;1.48.0;1.48;1.47.0;1.47;1.46.1;1.46.0;1.46;1.45.0;1.45;1.44.0;1.44;1.43.0;1.43;1.42.0;1.42;1.41.0;1.41;1.40.0;1.40;1.39.0;1.39;1.38.0;1.38;1.37.0;1.37;1.36.1;1.36.0;1.36;1.35.1;1.35.0;1.35;1.34.1;1.34.0;1.34;1.33.1;1.33.0;1.33
-- [ /usr/local/Cellar/cmake/3.4.1/share/cmake/Modules/FindBoost.cmake:553 ] Boost_USE_MULTITHREADED = TRUE
-- [ /usr/local/Cellar/cmake/3.4.1/share/cmake/Modules/FindBoost.cmake:555 ] Boost_USE_STATIC_LIBS = ON
-- [ /usr/local/Cellar/cmake/3.4.1/share/cmake/Modules/FindBoost.cmake:557 ] Boost_USE_STATIC_RUNTIME = 
-- [ /usr/local/Cellar/cmake/3.4.1/share/cmake/Modules/FindBoost.cmake:559 ] Boost_ADDITIONAL_VERSIONS = 
-- [ /usr/local/Cellar/cmake/3.4.1/share/cmake/Modules/FindBoost.cmake:561 ] Boost_NO_SYSTEM_PATHS = 
-- [ /usr/local/Cellar/cmake/3.4.1/share/cmake/Modules/FindBoost.cmake:613 ] Declared as CMake or Environmental Variables:
-- [ /usr/local/Cellar/cmake/3.4.1/share/cmake/Modules/FindBoost.cmake:615 ]   BOOST_ROOT = /usr/local/Cellar/boost/1.58.0
-- [ /usr/local/Cellar/cmake/3.4.1/share/cmake/Modules/FindBoost.cmake:617 ]   BOOST_INCLUDEDIR = /usr/local/Cellar/boost/1.58.0/include
-- [ /usr/local/Cellar/cmake/3.4.1/share/cmake/Modules/FindBoost.cmake:619 ]   BOOST_LIBRARYDIR = /usr/local/Cellar/boost/1.58.0/lib
-- [ /usr/local/Cellar/cmake/3.4.1/share/cmake/Modules/FindBoost.cmake:621 ] _boost_TEST_VERSIONS = 1.59.0;1.59;1.58.0;1.58;1.57.0;1.57;1.56.0;1.56;1.55.0;1.55;1.54.0;1.54;1.53.0;1.53;1.52.0;1.52;1.51.0;1.51;1.50.0;1.50;1.49.0;1.49;1.48.0;1.48;1.47.0;1.47;1.46.1;1.46.0;1.46;1.45.0;1.45;1.44.0;1.44;1.43.0;1.43;1.42.0;1.42;1.41.0;1.41;1.40.0;1.40;1.39.0;1.39;1.38.0;1.38;1.37.0;1.37;1.36.1;1.36.0;1.36;1.35.1;1.35.0;1.35;1.34.1;1.34.0;1.34;1.33.1;1.33.0;1.33
-- [ /usr/local/Cellar/cmake/3.4.1/share/cmake/Modules/FindBoost.cmake:690 ] Include debugging info:
-- [ /usr/local/Cellar/cmake/3.4.1/share/cmake/Modules/FindBoost.cmake:692 ]   _boost_INCLUDE_SEARCH_DIRS = /usr/local/Cellar/boost/1.58.0/include;/usr/local/Cellar/boost/1.58.0/include;/usr/local/Cellar/boost/1.58.0;PATHS;C:/boost/include;C:/boost;/sw/local/include
-- [ /usr/local/Cellar/cmake/3.4.1/share/cmake/Modules/FindBoost.cmake:694 ]   _boost_PATH_SUFFIXES = boost-1_59_0;boost_1_59_0;boost/boost-1_59_0;boost/boost_1_59_0;boost-1_59;boost_1_59;boost/boost-1_59;boost/boost_1_59;boost-1_58_0;boost_1_58_0;boost/boost-1_58_0;boost/boost_1_58_0;boost-1_58;boost_1_58;boost/boost-1_58;boost/boost_1_58;boost-1_57_0;boost_1_57_0;boost/boost-1_57_0;boost/boost_1_57_0;boost-1_57;boost_1_57;boost/boost-1_57;boost/boost_1_57;boost-1_56_0;boost_1_56_0;boost/boost-1_56_0;boost/boost_1_56_0;boost-1_56;boost_1_56;boost/boost-1_56;boost/boost_1_56;boost-1_55_0;boost_1_55_0;boost/boost-1_55_0;boost/boost_1_55_0;boost-1_55;boost_1_55;boost/boost-1_55;boost/boost_1_55;boost-1_54_0;boost_1_54_0;boost/boost-1_54_0;boost/boost_1_54_0;boost-1_54;boost_1_54;boost/boost-1_54;boost/boost_1_54;boost-1_53_0;boost_1_53_0;boost/boost-1_53_0;boost/boost_1_53_0;boost-1_53;boost_1_53;boost/boost-1_53;boost/boost_1_53;boost-1_52_0;boost_1_52_0;boost/boost-1_52_0;boost/boost_1_52_0;boost-1_52;boost_1_52;boost/boost-1_52;boost/boost_1_52;boost-1_51_0;boost_1_51_0;boost/boost-1_51_0;boost/boost_1_51_0;boost-1_51;boost_1_51;boost/boost-1_51;boost/boost_1_51;boost-1_50_0;boost_1_50_0;boost/boost-1_50_0;boost/boost_1_50_0;boost-1_50;boost_1_50;boost/boost-1_50;boost/boost_1_50;boost-1_49_0;boost_1_49_0;boost/boost-1_49_0;boost/boost_1_49_0;boost-1_49;boost_1_49;boost/boost-1_49;boost/boost_1_49;boost-1_48_0;boost_1_48_0;boost/boost-1_48_0;boost/boost_1_48_0;boost-1_48;boost_1_48;boost/boost-1_48;boost/boost_1_48;boost-1_47_0;boost_1_47_0;boost/boost-1_47_0;boost/boost_1_47_0;boost-1_47;boost_1_47;boost/boost-1_47;boost/boost_1_47;boost-1_46_1;boost_1_46_1;boost/boost-1_46_1;boost/boost_1_46_1;boost-1_46_0;boost_1_46_0;boost/boost-1_46_0;boost/boost_1_46_0;boost-1_46;boost_1_46;boost/boost-1_46;boost/boost_1_46;boost-1_45_0;boost_1_45_0;boost/boost-1_45_0;boost/boost_1_45_0;boost-1_45;boost_1_45;boost/boost-1_45;boost/boost_1_45;boost-1_44_0;boost_1_44_0;boost/boost-1_44_0;boost/boost_1_44_0;boost-1_44;boost_1_44;boost/boost-1_44;boost/boost_1_44;boost-1_43_0;boost_1_43_0;boost/boost-1_43_0;boost/boost_1_43_0;boost-1_43;boost_1_43;boost/boost-1_43;boost/boost_1_43;boost-1_42_0;boost_1_42_0;boost/boost-1_42_0;boost/boost_1_42_0;boost-1_42;boost_1_42;boost/boost-1_42;boost/boost_1_42;boost-1_41_0;boost_1_41_0;boost/boost-1_41_0;boost/boost_1_41_0;boost-1_41;boost_1_41;boost/boost-1_41;boost/boost_1_41;boost-1_40_0;boost_1_40_0;boost/boost-1_40_0;boost/boost_1_40_0;boost-1_40;boost_1_40;boost/boost-1_40;boost/boost_1_40;boost-1_39_0;boost_1_39_0;boost/boost-1_39_0;boost/boost_1_39_0;boost-1_39;boost_1_39;boost/boost-1_39;boost/boost_1_39;boost-1_38_0;boost_1_38_0;boost/boost-1_38_0;boost/boost_1_38_0;boost-1_38;boost_1_38;boost/boost-1_38;boost/boost_1_38;boost-1_37_0;boost_1_37_0;boost/boost-1_37_0;boost/boost_1_37_0;boost-1_37;boost_1_37;boost/boost-1_37;boost/boost_1_37;boost-1_36_1;boost_1_36_1;boost/boost-1_36_1;boost/boost_1_36_1;boost-1_36_0;boost_1_36_0;boost/boost-1_36_0;boost/boost_1_36_0;boost-1_36;boost_1_36;boost/boost-1_36;boost/boost_1_36;boost-1_35_1;boost_1_35_1;boost/boost-1_35_1;boost/boost_1_35_1;boost-1_35_0;boost_1_35_0;boost/boost-1_35_0;boost/boost_1_35_0;boost-1_35;boost_1_35;boost/boost-1_35;boost/boost_1_35;boost-1_34_1;boost_1_34_1;boost/boost-1_34_1;boost/boost_1_34_1;boost-1_34_0;boost_1_34_0;boost/boost-1_34_0;boost/boost_1_34_0;boost-1_34;boost_1_34;boost/boost-1_34;boost/boost_1_34;boost-1_33_1;boost_1_33_1;boost/boost-1_33_1;boost/boost_1_33_1;boost-1_33_0;boost_1_33_0;boost/boost-1_33_0;boost/boost_1_33_0;boost-1_33;boost_1_33;boost/boost-1_33;boost/boost_1_33
-- [ /usr/local/Cellar/cmake/3.4.1/share/cmake/Modules/FindBoost.cmake:714 ] location of version.hpp: /usr/local/Cellar/boost/1.58.0/include/boost/version.hpp
-- [ /usr/local/Cellar/cmake/3.4.1/share/cmake/Modules/FindBoost.cmake:738 ] version.hpp reveals boost 1.58.0
-- [ /usr/local/Cellar/cmake/3.4.1/share/cmake/Modules/FindBoost.cmake:824 ] guessed _boost_COMPILER = 
-- [ /usr/local/Cellar/cmake/3.4.1/share/cmake/Modules/FindBoost.cmake:834 ] _boost_MULTITHREADED = -mt
-- [ /usr/local/Cellar/cmake/3.4.1/share/cmake/Modules/FindBoost.cmake:877 ] _boost_RELEASE_ABI_TAG = -
-- [ /usr/local/Cellar/cmake/3.4.1/share/cmake/Modules/FindBoost.cmake:879 ] _boost_DEBUG_ABI_TAG = -d
-- [ /usr/local/Cellar/cmake/3.4.1/share/cmake/Modules/FindBoost.cmake:933 ] _boost_LIBRARY_SEARCH_DIRS_RELEASE = /usr/local/Cellar/boost/1.58.0/lib;/usr/local/Cellar/boost/1.58.0/lib;/usr/local/Cellar/boost/1.58.0/stage/lib;/usr/local/Cellar/boost/1.58.0/include/lib;/usr/local/Cellar/boost/1.58.0/include/../lib;/usr/local/Cellar/boost/1.58.0/include/stage/lib;PATHS;C:/boost/lib;C:/boost;/sw/local/lib_boost_LIBRARY_SEARCH_DIRS_DEBUG   = /usr/local/Cellar/boost/1.58.0/lib;/usr/local/Cellar/boost/1.58.0/lib;/usr/local/Cellar/boost/1.58.0/stage/lib;/usr/local/Cellar/boost/1.58.0/include/lib;/usr/local/Cellar/boost/1.58.0/include/../lib;/usr/local/Cellar/boost/1.58.0/include/stage/lib;PATHS;C:/boost/lib;C:/boost;/sw/local/lib
-- [ /usr/local/Cellar/cmake/3.4.1/share/cmake/Modules/FindBoost.cmake:1045 ] Searching for OPTIONAL_LIBRARY_RELEASE: boost_optional-mt-1_58;boost_optional-mt;boost_optional-mt-1_58;boost_optional-mt;boost_optional
-- [ /usr/local/Cellar/cmake/3.4.1/share/cmake/Modules/FindBoost.cmake:1087 ] Searching for OPTIONAL_LIBRARY_DEBUG: boost_optional-mt-d-1_58;boost_optional-mt-d;boost_optional-mt-d-1_58;boost_optional-mt-d;boost_optional-mt;boost_optional
-- [ /usr/local/Cellar/cmake/3.4.1/share/cmake/Modules/FindBoost.cmake:1153 ] Boost_FOUND = 1
CMake Error at   /usr/local/Cellar/cmake/3.4.1/share/cmake/Modules/FindBoost.cmake:1247 (message):
Unable to find the requested Boost libraries.

Boost version: 1.58.0

Boost include path: /usr/local/Cellar/boost/1.58.0/include

Could not find the following static Boost libraries:

      boost_optional

No Boost libraries were found.  You may need to set BOOST_LIBRARYDIR to the
directory containing Boost libraries or BOOST_ROOT to the location of
Boost.
Call Stack (most recent call first):
CMakeLists.txt:6 (find_package)


CMake Warning (dev) at CMakeLists.txt:9 (target_link_libraries):
Cannot specify link libraries for target "hash" which is not built by this
project.

CMake does not support this but it used to work accidentally and is being
allowed for compatibility.

Policy CMP0016 is not set: target_link_libraries() reports error if its
only argument is not a target.  Run "cmake --help-policy CMP0016" for
policy details.  Use the cmake_policy command to set the policy and
suppress this warning.
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Configuring incomplete, errors occurred!

我通过运行cmake来执行.

I execute by running cmake .

编辑.问题已解决.正确的CMakeLists.txt应该是:

Edit. The problem has been solved. The correct CMakeLists.txt should be :

cmake_minimum_required(VERSION 2.6)
SET(BOOST_ROOT /usr/local/Cellar/boost/1.58.0)
SET(BOOST_INCLUDEDIR /usr/local/Cellar/boost/1.58.0/include)
find_package(Boost REQUIRED)

include_directories(${BOOST_INCLUDEDIR})
add_executable(myProgram main.cc)

发生此错误是因为Boost.Optional是仅标头文件,我不需要为其找到lib.

The error occurred because Boost.Optional is a header-only file and I do not need to locate the lib for it.

推荐答案

Boost.可选的是head头库:

Boost.Optional is a head only libraries:

请参见 http://www.boost .org/doc/libs/1_60_0/libs/optional/doc/html/index.html

find_package中的COMPONENTS仅对于内置库是必需的.因此,您只需要编写:

The COMPONENTS in find_package is required only for built libraries. So, you only need to write:

find_package(Boost 1.58.0 REQUIRED)

请参阅类似的链接: CMake Boost 1.59.0几何

这篇关于CMake找不到Boost库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆