gpt4 book ai didi

c++ - 我如何使用 find_package 链接 CMakeList.txt 中的 Boost(不在 usr/include 中)

转载 作者:行者123 更新时间:2023-11-30 05:21:19 28 4
gpt4 key购买 nike

现在,我需要使用 "find_package(Boost 1.62.0 COMPONENTS program_options serialization system filesystem thread REQUIRED)" 将一些库包含到我的程序中,但我的 boost 库安装在其他目录中,不在默认目录**(usr/include..)**。现在出现以下错误:

 CMake Error at /usr/share/cmake/Modules/FindBoost.cmake:1138 (message):  
Unable to find the requested Boost libraries.
Boost version: 1.41.0
Boost include path: /usr/includ
Detected version of Boost is too old.
Requested version was 1.62 (or
newer).

我给出了我的 CMakelist.txt 的一些内容:

SET(BOOST_DIR /home/mingjli/folder_Mingjie/Software/boost_1.62.0/include/boost)
SET(BOOST_LIB /home/mingjli/folder_Mingjie/Software/boost_1.62.0/lib)
INCLUDE (${Source_Path}/IndexerLauncher.cmake NO_POLICY_SCOPE)
INCLUDE_DIRECTORIES(${BOOST_DIR})
LINK_DIRECTORIES(${BOOST_LIB})
INCLUDE_DIRECTORIES(${Source_Path})
ADD_EXECUTABLE (indexer_launcher ${IndexerLauncher})
TARGET_LINK_LIBRARIES (indexer_launcher nearest_search_lib)
target_link_libraries( indexer_launcher ${Boost_LIBRARIES} )

谢谢!!

最佳答案

Boost version: 1.41.0  
^^

这意味着,您安装了 boost 版本 1.41.0,但您请求的是 1.62.0。您可以更新 boost 或更改最低 boost 版本要求:

find_package(Boost 1.41.0 COMPONENTS program_options serialization system filesystem thread REQUIRED)
^^

您的 CMakeLists.txt 中应该没有什么特别的东西来包含 Boost。这是一个适合我的示例:

cmake_minimum_required(VERSION 2.8)
find_package(Boost REQUIRED filesystem system)
include_directories(${Boost_INCLUDE_DIRS})
target_link_libraries(mytarget ${Boost_LIBRARIES})

更新:如果您无法更新您的系统 boost 版本,您可以将 boost 安装到您的主文件夹中:

  1. 从 www.boost.org 下载 boost 源
  2. 编译并安装新的 boost 到您的主目录:

    b2 toolset=gcc install --prefix=/home/user/boost

编译 boost 后 - 你可以从/home/user/boost 使用它:

cmake .. -DBOOST_ROOT=/home/user/boost

关于c++ - 我如何使用 find_package 链接 CMakeList.txt 中的 Boost(不在 usr/include 中),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40211827/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com