我正在尝试使用来自NDK(r18.1.5063045)的clang
为Android编译FFmpeg 4.0。我的主机体系结构是Mac OS。
这是我的配置命令:
./configure \
--target-os=android \
--arch=armv7-a \
--enable-cross-compile \
--cc=${ANDROID_NDK}/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang \
--enable-shared \
--disable-static
此操作成功完成。因此,我运行make -j8
并收到以下错误:
In file included from libavfilter/vf_mestimate.c:22:
In file included from ./libavcodec/mathops.h:40:
./libavcodec/arm/mathops.h:90:26: error: invalid instruction mnemonic 'itt'
"cmp %1, %2 \n\t"
^
<inline asm>:3:2: note: instantiated into assembly here
itt gt
^~~
有什么想法会导致这种情况吗?
答案 0 :(得分:4)
我怀疑Clang是针对主机操作系统而不是arm32。使用standalone toolchain可解决此问题。我注意到构建系统仍在使用主机strip
工具(无法处理手臂二进制文件),因此我通过将--strip
传递给ffmpeg的配置脚本来解决了这个问题。
${ANDROID_NDK}/build/tools/make_standalone_toolchain.py \
--arch arm --api 16 --install-dir /tmp/standalone-toolchain
./configure \
--target-os=android \
--arch=armv7-a \
--enable-cross-compile \
--cc=/tmp/standalone-toolchain/bin/clang \
--strip=/tmp/standalone-toolchain/bin/arm-linux-androideabi-strip \
--enable-shared \
--disable-static
make -j...
然后构建失败,并在libavdevice / v4l2.c中出现错误:
CC libavdevice/v4l2.o
libavdevice/v4l2.c:135:9: error: assigning to 'int (*)(int, unsigned long, ...)' from incompatible type
'<overloaded function type>'
SET_WRAPPERS();
^~~~~~~~~~~~~~
libavdevice/v4l2.c:121:17: note: expanded from macro 'SET_WRAPPERS'
s->ioctl_f = prefix ## ioctl; \
^ ~~~~~
/tmp/standalone-toolchain/bin/../sysroot/usr/include/bits/ioctl.h:56:5: note: candidate function has type mismatch at 2nd
parameter (expected 'unsigned long' but has 'unsigned int')
int ioctl(int __fd, unsigned __request, ...) __overloadable __enable_if(1, "") __RENAME(ioctl);
^
/tmp/standalone-toolchain/bin/../sysroot/usr/include/bits/ioctl.h:36:5: note: candidate function has type mismatch at 2nd
parameter (expected 'unsigned long' but has 'int')
int ioctl(int __fd, int __request, ...);
^
关于ioctl的第二个参数的类型存在分歧。 glibc使用unsigned long
类型声明它:
int ioctl(int fd, unsigned long request, ...);
POSIX和Bionic(和音乐)用int
声明:
int ioctl(int fildes, int request, ... /* arg */);
PulseAudio and musl发生了类似的问题,因此我对ffmpeg应用了相同的修复程序:
diff --git a/libavdevice/v4l2.c b/libavdevice/v4l2.c
index 10a0ff0dd6..1b9c6e760b 100644
--- a/libavdevice/v4l2.c
+++ b/libavdevice/v4l2.c
@@ -95,7 +95,11 @@ struct video_data {
int (*open_f)(const char *file, int oflag, ...);
int (*close_f)(int fd);
int (*dup_f)(int fd);
+#ifdef __GLIBC__
int (*ioctl_f)(int fd, unsigned long int request, ...);
+#else
+ int (*ioctl_f)(int fd, int request, ...);
+#endif
ssize_t (*read_f)(int fd, void *buffer, size_t n);
void *(*mmap_f)(void *start, size_t length, int prot, int flags, int fd, int64_t offset);
int (*munmap_f)(void *_start, size_t length);
此后,项目成功构建。
FWIW:该项目还使用以下更改为arm64构建:
--arch arm64
--api 21
--arch=aarch64
--strip=/.../aarch64-linux-android-strip