Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#7130 closed defect (worksforme)

Android compilation broken with FFmpeg 3.4.2

Reported by: Don Turner Owned by:
Priority: normal Component: avcodec
Version: git-master Keywords: android
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

Summary of the bug:

When compiling FFmpeg 3.4.2 for Android using the latest version of the Android NDK (16.1.4479499) the following error is produced:

libavcodec/aaccoder.c: In function 'search_for_ms':
libavcodec/aaccoder.c:803:25: error: expected identifier or '(' before numeric constant

int B0 = 0, B1 = 0;

How to reproduce:

#!/bin/bash

PLATFORM=${ANDROID_NDK}/platforms/android-16/arch-arm

./configure \
--prefix=build/armeabi-v7a \
--target-os=linux \
--arch=arm \
--cc=${ANDROID_NDK}/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-gcc \
--nm=${ANDROID_NDK}/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-nm \
--strip=${ANDROID_NDK}/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-strip \
--cross-prefix=arm-linux-androideabi- \
--extra-libs="-lgcc" \
--sysroot=${ANDROID_NDK}/sysroot \
--extra-cflags="-I${ANDROID_NDK}/sysroot/usr/include/arm-linux-androideabi" \
--extra-ldflags="-Wl,-rpath-link=$PLATFORM/usr/lib -L$PLATFORM/usr/lib -nostdlib -lc -lm -ldl -llog" \
--enable-cross-compile \
--enable-small \
--disable-programs \
--disable-doc \
--enable-shared \
--disable-static

Then execute:

make

Expected outcome:

FFmpeg compiles without error

Actual outcome:

The following error is produced:

libavcodec/aaccoder.c: In function 'search_for_ms':
libavcodec/aaccoder.c:803:25: error: expected identifier or '(' before numeric constant

int B0 = 0, B1 = 0;

The problem seems to be a name clash with #define B0 in $ANDROID_NDK/sysroot/usr/include/asm-generic/termbits.h

Here's a blog post from someone experiencing the same issue: https://medium.com/@piyush1995bhandari/cross-compiling-ffmpeg-for-android-545a1cfca31e

Change History (4)

comment:1 by Carl Eugen Hoyos, 7 years ago

Please understand that this has to be fixed in current FFmpeg git head, I don't think there is release support for Android.
Unfortunately, I see all kinds of compilation and linking issues (atomics and mmap64 and friends) but I don't get a compile error for aaccoder.c.

comment:2 by Don Turner, 7 years ago

Getting the same error on the current git head.

comment:3 by Carl Eugen Hoyos, 7 years ago

Keywords: android added
Resolution: worksforme
Status: newclosed
Version: unspecifiedgit-master

The following succeeds here (for older targets, you have to disable some features of FFmpeg, aaccoder.o compilation also works for Android 16), assuming you downloaded and extracted NDK r16 and FFmpeg into the same directory:

$ android-ndk-r16b/build/tools/make_standalone_toolchain.py --arch arm --api 21 --install-dir ndk-arm-21
$ cd FFmpeg
$ ./configure --cross-prefix=../ndk-arm-21/bin/arm-linux-androideabi- --sysroot=../ndk-arm-21/sysroot --arch=arm --target-os=android --disable-static --enable-shared --enable-small --disable-programs

comment:4 by Don Turner, 7 years ago

Thank you for this fast resolution. The issue was with the --target-os=linux, changing to --target-os=android fixed the issue, no need for a standalone toolchain.

Note: See TracTickets for help on using tickets.