【问题标题】:Cmake can find boost but not boost coreCmake可以找到boost但不能找到boost core
【发布时间】:2018-05-08 20:04:38
【问题描述】:

我已经在 Ubuntu 上安装了 libboost-all-dev。

Cmake 3.10.2 可以找到 boost 但找不到 "boost_core"。

当我将查找包行更改为:

find_package(Boost REQUIRED COMPONENTS core)

然后它抱怨找不到“boost_core”。

其实我只需要boost/iterator...

如何让 cmake 找到它?

谢谢。

CMakeLists.txt:

cmake_minimum_required(VERSION 3.10)
project(test_boost_iterator)

set(CMAKE_CXX_STANDARD 11)

find_package(Boost REQUIRED)
include_directories(${Boost_INCLUDE_DIR})
add_definitions( "-DHAS_BOOST" )

add_executable(test_boost_iterator main.cpp)

成功消息(在替换find_package 行之前):

-- Boost version: 1.65.1
-- Configuring done
-- Generating done

错误信息(替换find_package 行后)

  Unable to find the requested Boost libraries.

  Boost version: 1.65.1

  Boost include path: /usr/include

  Could not find the following Boost libraries:

          boost_core

  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)

【问题讨论】:

  • 在您的代码 sn-p 中,您没有为 find_package 指定 COMPONENTS。
  • 是的。这在我将find_package 行更改为find_package(Boost REQUIRED COMPONENTS core) 之前有效

标签: boost cmake


【解决方案1】:

据我所知,没有这样的 boost 库 core。你可以检查一个库是否应该链接here。 而Boost.Iterator 是一个只有头文件的库,所以你不需要链接任何东西。只需包括<boost/iterator/...>。如果您不能包含,请检查这些包含是否确实存在于您的本地 boost 发行版中。

我检查了 boost::counting_iterator<int> 并且一切正常。

【讨论】:

  • 这在不使用 cmake 的情况下工作。但是 boost 可以在非标准位置,特别是对于没有管理员权限的安装。
  • 如果在非标准位置,将其指定为自定义包含目录。我不认为 FindBoost 会找到它,如果它位于某个深奥的地方。你能说出你的问题是什么吗?为什么要更改find_package(Boost REQUIRED)?
猜你喜欢
  • 2011-04-18
  • 1970-01-01
  • 2011-12-26
  • 2022-01-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多