gpt4 book ai didi

boost - cmake 找不到 boost 库

转载 作者:行者123 更新时间:2023-12-02 00:08:29 32 4
gpt4 key购买 nike

我想交叉编译一个使用 boost 库(正则表达式)的简单 main.cpp,目标平台是树莓派(raspbian)。我已经从 apt-get 安装了 libboost-all-dev 包。所以 header 在 raspi 中。

然后从另一个教程中,我被告知通过 rsync 将/usr 和/lib 复制到我的主机系统。所以我复制到我的主机目录 (/home/vitor/local/{usr,lib})

我有这个 CMakeLists.txt

cmake_minimum_required(VERSION 2.8)
project(BoostRegex)

set(Boost_ADDITIONAL_VERSIONS "1.49" "1.49.0" )
set(BOOST_ROOT /home/vitor/local/usr/lib)
set(BOOST_INCLUDEDIR /home/vitor/local/usr/include)
set(BOOST_LIBRARYDIR /home/vitor/local/usr/lib)

add_definitions(-DBOOST_ALL_NO_LIB)

find_package(Boost COMPONENTS system test regex REQUIRED)

message(status " ** Boost Root: ${BOOST_ROOT} **")
message(status " ** Boost Include: ${BOOST_INCLUDEDIR} **")
message(status " ** Boost Libraries Dirs: ${BOOST_LIBRARY_DIRS} **")
message(status " ** Boost Librraries: ${BOOST_LIBRARYDIR} **")

include_directories(${BOOST_INCLUDEDIR})
link_directories(${BOOST_LIBRARYDIR})

add_executable(BoostRegex BoostRegex.cpp)
target_link_libraries(BoostRegex ${Boost_LIBRARIES})

使用的命令是:

cmake -DCMAKE_TOOLCHAIN_FILE=/home/vitor/bin/raspi/cmaketoolchain/toolchain.cmake ../src/

cmake 没有找到测试库。/home/vitor/usr/lib 中的 ls 告诉我:

libboost_system.so
libboost_regex.so
libboost_unit_test_framework-mt.so

但是没有找到 libboost_test.so。

最后,这是我得到的错误:

Unable to find the requested Boost libraries.
Boost version: 1.49.0
Boost include path: /home/vitor/local/usr/include
The following Boost libraries could not be found:

boost_test

Some (but not all) of the required Boost libraries were found. You may
need to install these additional Boost libraries. Alternatively, 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:12 (find_package)


status ** Boost Root: /home/vitor/local/usr/lib **
status ** Boost Include: /home/vitor/local/usr/include **
status ** Boost Libraries Dirs: **
status ** Boost Librraries: /home/vitor/local/usr/lib **
-- Configuring incomplete, errors occurred!

如果我从所需的组件中删除测试。该命令工作正常。

ps.: 在我的 toolchain.cmake 文件中,我只能通过这两行找到库:

SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER)

如何找到 libboost_test.so?

最佳答案

我不认为有一个名为“测试”的 boost 目标;它应该是“unit_test_framework”。

尝试更改为:

find_package(Boost COMPONENTS system unit_test_framework regex REQUIRED)

关于boost - cmake 找不到 boost 库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16903585/

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