设置 CMAKE_PREFIX_PATH 不适用于 Android 工具链 [英] set CMAKE_PREFIX_PATH not working with Android Toolchain

查看:44
本文介绍了设置 CMAKE_PREFIX_PATH 不适用于 Android 工具链的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Android CMake 工具链将 CMake C 和 C++ 游戏移植到 Android.

I am porting a CMake C and C++ game to Android using the Android CMake Toolchain.

项目的库依赖项存储在 PROJECTDIR/android_dependencies 中,我已将以下代码添加到 CMake 文件中以使用它们(我检查了目录和文件是否存在).

The library dependencies for the project are stored in PROJECTDIR/android_dependencies and I have added the following code to the CMake file to use them (I checked that the directories and files exist).

set(CMAKE_PREFIX_PATH "${PROJECT_SOURCE_DIR}/android_dependencies/${ANDROID_ABI}")

但是我的项目还是说找不到像 OpenAL 这样的依赖(所有的库都被复制了).

But my project still says it could not find the dependencies like OpenAL (all the libraries are copied).

如果我将库复制到 $NDK/platforms/android-9/usr/lib 并将文件包含到 $NDK/platforms/android-9/usr/include 项目编译正确.

If I copy the libraries to $NDK/platforms/android-9/usr/lib and include files to $NDK/platforms/android-9/usr/include the project compiles correctly.

我做错了什么?

我使用的是 Ubuntu 16.04 64 位

I am using Ubuntu 16.04 64-bit

推荐答案

几乎所有的工具链都设置了变量 CMAKE_SYSROOT 变量.除了其他内容之外,此变量可能会向 find_* CMake 命令使用的路径添加额外的根".但默认情况下也会搜索非根"路径.

Almost all toolchains set variable CMAKE_SYSROOT variable. This variable, aside other things, may add additional "root" to paths, used by find_* CMake commands. But by default also "non-rooted" paths are searched too.

某些工具链可能会设置变量CMAKE_FIND_ROOT_PATH_MODE_*,这些变量会调整CMAKE_SYSROOT 在搜索事物时的行为.

Some toolchains may set variable(s) CMAKE_FIND_ROOT_PATH_MODE_*, which adjust behavior of CMAKE_SYSROOT when search things.

例如,将变量 CMAKE_FIND_ROOT_PATH_MODE_LIBRARY 设置为 ONLY 使 find_library 仅搜索 根"路径,因此 无法找到位于主机上的库.(此规则有例外,请参阅 find_library 的文档更多细节).

E.g., setting variable CMAKE_FIND_ROOT_PATH_MODE_LIBRARY to ONLY makes find_library to search only "rooted" paths, so one cannot find libraries located on the host. (There are exceptions from this rule, see documentation for find_library for more details).

脚本 CMakeLists.txt 能够更改 CMAKE_FIND_ROOT_PATH_MODE_* 变量的值,并将它们设置为 BOTH (或只是清除它们).但通常这可能会破坏工具链(因此其他 find_library 调用会在主机上找到一些东西,而它们本来打算根本找不到任何东西).

Script CMakeLists.txt is able to change value of CMAKE_FIND_ROOT_PATH_MODE_* variables, and set them to BOTH (or just clear them). But generally this may break toolchain (so other find_library calls will find something on host while they are intended to not find anything at all).

首选方法是遵循工具链策略,并在构建包之前将所有包的 prerequesites 安装到 sysroot 中.

Preferred way is to follow toolchain strategy and install all package's prerequesites into sysroot before building the package itself.

这篇关于设置 CMAKE_PREFIX_PATH 不适用于 Android 工具链的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆