如何指向find_package()
我的“自定义”目录$SYSROOT/usr/lib/arm-linux-gnueabihf/
以便它可以找到libz.so
?
我在这个位置有一个图书馆:
/home/user/bla/sysroot/usr/lib/arm-linux-gnueabihf/libz.so
带有可以在此处找到的标题:
/home/user/bla/sysroot/usr/include/zlib.h
使用 CMake 我尝试:
cmake_minimum_required(VERSION 3.18)
find_package(ZLIB REQUIRED)
结果是:
CMake Error at /home/user/cmake/linux/share/cmake-3.19/Modules/FindPackageHandleStandardArgs.cmake:218 (message):
Could NOT find ZLIB (missing: ZLIB_LIBRARY) (found version "1.2.11")
所以 CMake 找不到ZLIB_LIBRARY
( libz.so
) 但它可以1.2.11
从头文件中解析版本 ( )。
我在 CMake 中设置了我的 SYSROOT,如下所示:
SET(CMAKE_FIND_ROOT_PATH "${toolchain_dir}/sysroot/")
但似乎 CMake 不知道 usr/lib/ arm-linux-gnueabihf / libz.so。
我试过的
我试图给 HINTS 或 PATH 来find_package
喜欢这个:
find_package(ZLIB REQUIRED HINTS "${sysroot_dir}/usr/lib/arm-linux-gnueabihf/" NO_DEFAULT_PATH)
或像这样:
find_package(ZLIB REQUIRED PATH "${sysroot_dir}/usr/lib/arm-linux-gnueabihf/" NO_DEFAULT_PATH)
但它会导致此错误消息:
CMake Error at CMakeLists.txt:12 (find_package):
Could not find a package configuration file provided by "ZLIB" with any of
the following names:
ZLIBConfig.cmake
zlib-config.cmake
Add the installation prefix of "ZLIB" to CMAKE_PREFIX_PATH or set
"ZLIB_DIR" to a directory containing one of the above files. If "ZLIB"
provides a separate development package or SDK, be sure it has been
installed.
额外信息
这是我使用的工具链文件的内容(针对树莓派 4)-DCMAKE_TOOLCHAIN_FILE=/path/to/toolchain.cmake
# Define our host system
SET(CMAKE_SYSTEM_NAME Linux)
SET(CMAKE_SYSTEM_VERSION 1)
# toolchain
set(toolchain_dir "/home/user/bla")
set(sysroot_dir "${toolchain_dir}/sysroot")
SET(CMAKE_C_COMPILER "${toolchain_dir}/tools/gcc-linaro-7.5.0-2019.12-i686_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc")
SET(CMAKE_CXX_COMPILER "${toolchain_dir}/tools/gcc-linaro-7.5.0-2019.12-i686_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-g++")
# Define the sysroot path for the RaspberryPi distribution
SET(CMAKE_FIND_ROOT_PATH "${toolchain_dir}/sysroot/")
message(STATUS "${CMAKE_FIND_ROOT_PATH}")
# Use our definitions for compiler tools
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
# Search for libraries and headers in the target directories only
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)