gpt4 book ai didi

没有 sysroot 的 Android NDK 编译

转载 作者:行者123 更新时间:2023-11-30 02:24:19 31 4
gpt4 key购买 nike

我正在尝试根据编译标志(通过将 Application.mk 的路径动态传递给 ndk-build 命令)为 Android NDK 的多个体系结构和多个 API 级别编译源代码。直到r12一切顺利。现在我试图将我的构建系统更新到最新的 NDK r15c,发现它从“android-ndk/sysroot/...”路径获取 header ,而不是依赖于 Application.mk 文件中的 APP_PLATFORM 标志

APP_PLATFORM                   := android-19

r12b NDK 的日志:

-I/data/android/android-ndk-r10d/platforms/android-19/arch-arm/usr/include

当我尝试 ndk-build (V=1) 的详细日志时,存在上述包含路径。

r15c NDK 的日志:

--sysroot
/home/airwatch/Android/android-ndk/sysroot
-isystem
/home/airwatch/Android/android-ndk/sysroot/usr/include/arm-linux-androideabi

当我为 r15c NDK 尝试详细日志时,存在上述包含路径。

将无法配置 Standalone Toolchain由于我的项目要求。无论如何要摆脱这个 sysroot?

最佳答案

正如上面评论中提到的,这里有完整的解释:https://android.googlesource.com/platform/ndk/+/master/docs/UnifiedHeaders.md

Unified Headers

Before NDK r14, we had a set of libc headers for each API version. In many cases these headers were incorrect. Many exposed APIs that didn‘t exist, and others didn’t expose APIs that did.

In NDK r14 (as an opt in feature) we unified these into a single set of headers, called unified headers. This single header path is used for every platform level. API level guards are handled with #ifdef. These headers can be found in prebuilts/ndk/headers.

Unified headers are built directly from the Android platform, so they are up to date and correct (or at the very least, any bugs in the NDK headers will also be a bug in the platform headers, which means we're much more likely to find them).

In r15 unified headers are used by default. In r16, the old headers have been removed.

Known Issues

  • Standalone toolchains using GCC are not supported out of the box. To use GCC, pass -D__ANDROID_API__=$API when compiling. Note: this is not something we will be fixing.

Supporting Unified Headers in Your Build System

  1. Unified headers require only a few changes compared to using the deprecated NDK headers. For reference, this patch added support to ndk-build: https://android-review.googlesource.com/c/239934/

The compile time sysroot is now $NDK/sysroot. Previously this was $NDK/platforms/android-$API/arch-$ARCH.

  1. Pass -isystem $NDK/sysroot/usr/include/$TRIPLE when compiling. The triple has the following mapping:

Arch Triple
ARM arm-linux-androideabi
ARM64 aarch64-linux-android
MIPS mipsel-linux-android
MIPS64 mips64el-linux-android
x86 i686-linux-android
x86_64 x86_64-linux-android

This is needed for architecture specific headers such as those in asm/ and machine/. We plan to teach Clang's driver to automatically search the architecture specific include directory, but that has yet to be done.

  1. Pass -D__ANDROID_API__=$API when compiling. This define used to be provided by <android/api-level.h>, but with only one set of headers this is no longer possible. In the future we will look in to adding -mandroid-version or similar to Clang so this is automatic.

  2. At link time, change nothing. All link time build behavior should match the deprecated headers behavior. --sysroot should still point to $NDK/platforms/android-$API/arch-$ARCH/.

关于没有 sysroot 的 Android NDK 编译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45504340/

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