Android 构建系统、NEON 和非 NEON 构建 [英] Android build system, NEON and non-NEON builds

查看:25
本文介绍了Android 构建系统、NEON 和非 NEON 构建的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为 armv6 构建我的库,如果设备支持,我会在运行时启用一些霓虹灯代码.霓虹灯代码使用霓虹灯内在函数,为了能够编译它,我必须启用 armeabi-v7a,但这会影响常规 c 代码(它在某些低端设备上会损坏).

I want to build my library for armv6, and there is some neon code that I enable at runtime if the device supports it. The neon code uses neon intrinsics, and to be able to compile it, I must enable armeabi-v7a, but that affects regular c-code (it becomes broken on some low-end devices).

所以,如果android构建系统不是过度干扰,我就不必问问题了,但是我似乎没有办法为armv6编译一个文件,为arm7-neon编译另一个文件.

So, if the android build system wasn't excessively intrusive, I wouldn't have to ask questions, but it seems that there is no way for me to compile one file for armv6 and the other file for arm7-neon.

如果可行,有人可以提供任何线索吗?

Can anybody give any clues if that's doable?

编辑
在尝试回复和浪费互联网墨水之前,应该清楚这些是要点:
1) 只制作一个库.
2) 构建在 armv6(preneon 设备,例如 armeabi)上运行的构建.
3) 允许此构建还包含 NEON 代码(可以根据运行时 CPU 检测执行;CPU 检测不在问题范围内).
4) NEON 代码来自 c/cpp 文件,并使用 Neon 内在函数编写.

Edit
Before trying to reply and wasting internet-ink, it should be clear that these are the main points:
1) make only ONE lib.
2) make build that runs on armv6 (pre neon devices, e.g. armeabi).
3) allow this build to also contain NEON code (which could be executed based on run-time cpu detection; cpu detection is outside the scope of the question).
4) NEON code comes from a c/cpp file and is written using neon intrinsics.

省略这些要求的任何部分完全失去了问题的重点

推荐答案

我最近找到了另一种解决 NDK 局限性的方法.我的案例与 NEON 无关,但对您来说,同样的 hack 也可以完成这项工作.

I have recently found another way to work around the limitations of NDK. My case was not related to NEON, but for you the same hack could do the job.

诀窍是使用 NDK 现有的标签"机制为一堆文件指定特殊的 CFLAGS.这就是你的做法:

The trick is to use the existing "tag" mechanism of NDK to specify special CFLAGS for a bunch of files. This is how you do it:

首先,列出特定于霓虹灯的来源.您不能使用 中所述的 .neon 后缀docs/CPU-ARM-NEON.html 因为 build-binary.mk 会发现您的目标不是 armeabi-v7a.我使用以下技术:

First, list the neon-specific sources. You cannot use the .neon suffix as described in docs/CPU-ARM-NEON.html because build-binary.mk will find that you are not targeting armeabi-v7a. I use the following technique:

LOCAL_NEON_SRC_FILES := imgproc/neon_utils.c \
                        videoproc/usingneon.cpp
LOCAL_SRC_FILES := main.c \
                   imgproc/img.c \
                   videoproc/video.cpp

LOCAL_SRC_FILES += $(LOCAL_NEON_SRC_FILES)

现在,为 NEON 定义 CFLAGS:

Now, define the CFLAGS for NEON:

LOCAL_NEON_CFLAGS := -mfloat-abi=softfp -mfpu=neon -march=armv7

最后,将以下神奇的行添加到您的 Android.mk 中:

Finally, add the following magical line to your Android.mk:

TARGET-process-src-files-tags += $(call add-src-files-target-cflags, $(LOCAL_NEON_SRC_FILES), $(LOCAL_NEON_CFLAGS))

如果您有多个二进制文件要构建,您可能希望 $(LOCAL_NEON_SRC_FILES)

If you have more than one binary to build, you will probably want $(LOCAL_NEON_SRC_FILES) to be reset by

include $(CLEAR_VARS)

为此,请将以下内容添加到您的 Android.mkApplication.mk:

For this, add the following to your Android.mk or to Application.mk:

modules-LOCALS += NEON_SRC_FILES

注意:我没有为 NEON 尝试过这种魔法,我需要它用于完全不同的目的.您可能需要进行一些调整才能为您的文件和项目实现所需的编译选项.我正在使用 NDK r.8b,但我没有检查这是否适用于早期(或更高版本)的版本.

Note: I have not tried this magic for NEON, I needed it for entirely different purposes. You may need some adaptations to achieve the desired compilation options for your files, and for your project. I am using NDK r.8b, and I did not check if this would work on earlier (or later) versions.

这篇关于Android 构建系统、NEON 和非 NEON 构建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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