您好我有一个使用 LibArchive 库和 CMake 的 C++ 库。顶级 CMake 需要使用 CMakeLists.txt 中的 find_package 的 LibArchive 3.0:
find_package(LibArchive 3.0 REQUIRED)
我已经在我的 Ubuntu 开发机器上安装了 LibArchive:
$sudo apt install build-essential libarchive-dev
并且可以成功构建 x86 架构的库。
但是,当我尝试使用适用于 arm64 的 Android NDK 工具链构建此库以便可以使用以下命令将其用作 Android 应用程序内的本机库时,我收到错误“找不到 LibArchive”:
~/SampleLib/build $ cmake -DCMAKE_TOOLCHAIN_FILE=/home/username/Android/Sdk/ndk/21.4.7075529/build/cmake/android.toolchain.cmake -DANDROID_ABI=arm64-v8a -DAPPLICATION=android ..
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /home/username/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Error at /home/username/.local/share/cmake-3.19/Modules/FindPackageHandleStandardArgs.cmake:218 (message):
Could NOT find LibArchive (missing: LibArchive_LIBRARY
LibArchive_INCLUDE_DIR) (Required is at least version "3.0")
Call Stack (most recent call first):
/home/username/.local/share/cmake-3.19/Modules/FindPackageHandleStandardArgs.cmake:582 (_FPHSA_FAILURE_MESSAGE)
/home/username/.local/share/cmake-3.19/Modules/FindLibArchive.cmake:60 (find_package_handle_standard_args)
CMakeLists.txt:7 (find_package)
如何在 Android NDK 工具链中安装 LibArchive?
我想也许我需要 git clone libarchive 并使用 NDK 工具链构建它,希望通过添加路径,NDK 工具链 cmake 可以找到它,但我得到构建错误:
~/libarchive (master) $ cmake -DCMAKE_TOOLCHAIN_FILE=/home/username/Android/Sdk/ndk/21.4.7075529/build/cmake/android.toolchain.cmake -DANDROID_ABI=arm64-v8a
~/libarchive (master) $ make
Scanning dependencies of target archive
[ 0%] Building C object libarchive/CMakeFiles/archive.dir/archive_acl.c.o
In file included from /home/username/libarchive/libarchive/archive_acl.c:40:
In file included from /home/username/libarchive/libarchive/archive_acl_private.h:35:
In file included from /home/username/libarchive/libarchive/archive_string.h:49:
/home/username/libarchive/libarchive/archive.h:101:10: fatal error: 'android_lf.h' file not found