【发布时间】:2020-06-08 14:33:25
【问题描述】:
我是使用 CMake 的新手。我正在为运行嵌入式 Linux 的设备在 Debian 主机上使用 CMake 进行交叉编译。下面是我的 CMake 工具链文件:
INCLUDE(CMakeForceCompiler)
SET(CMAKE_SYSTEM_NAME Linux) # this one is important
SET(CMAKE_SYSTEM_VERSION 1) # this one not so much
# this is the location of the amd64 toolchain targeting the device
SET(CMAKE_C_COMPILER /home/bsp/bsp-linux/bin/arm-linux-gnueabi-gcc)
# this is the file system root of the target
SET(CMAKE_FIND_ROOT_PATH /home/bsp/bsp-linux/sysroot)
# search for programs in the build host directories
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
# for libraries and headers in the target directories
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
SET(OPENSSL_ROOT_DIR /home/bsp/bsp-linux/sysroot/usr/lib)
SET(OPENSSL_INCLUDE_DIR /home/bsp/bsp-linux/sysroot/usr/include/openssl)
我遇到 CMake 找不到 curl 的错误,如下所示:
Cross compiling not using pkg-config
-- Could NOT find CURL (missing: CURL_LIBRARY CURL_INCLUDE_DIR)
CMake Error at /usr/share/cmake-3.13/Modules/FindPackageHandleStandardArgs.cmake:137 (message):
Could NOT find CURL (missing: CURL_LIBRARIES)
Call Stack (most recent call first):
/usr/share/cmake-3.13/Modules/FindPackageHandleStandardArgs.cmake:378 (_FPHSA_FAILURE_MESSAGE)
c-utility/CMakeLists.txt:522 (find_package_handle_standard_args)
libcurl 位于以下文件夹中目标的 sysroot 中:
/home/bsp/bsp-linux/sysroot/usr/lib/libcurl.so
为什么 CMake 找不到这个,我如何告诉 CMake 在这里找到库?谢谢。
【问题讨论】:
-
您是否尝试像使用 OpenSSL 一样设置 CURL 根目录:
SET(CURL_ROOT_DIR ... )? -
顺便说一句,对于真正的 sysroot 有一个特殊的 CMake 变量:CMAKE_SYSROOT。此变量中设置的目录与
CMAKE_FIND_ROOT_PATH变量中列出的目录具有相同的属性,因此CMAKE_FIND_ROOT_PATH_MODE_*设置也会影响此目录。此外,CMake 会自动为编译器生成--sysroot选项。
标签: c linux cmake libcurl toolchain