[FFmpeg-user] compiling for android

Patrick Shirkey pshirkey at boosthardware.com
Wed Jul 9 12:19:19 CEST 2014

On Wed, July 9, 2014 7:37 pm, Carl Eugen Hoyos wrote:
> Patrick Shirkey <pshirkey <at> boosthardware.com> writes:
>> It utilises ./configure too but has additional code
>> which modifies various config files before building
> This is one of the reasons why you definitely shouldn't
> use this script.
> [...]
>> > Why are --extra-cflags needed?
>> No specific reason. They worked for the script above
>> without x264 so I was starting from there.
>>  ./configure --arch=arm --target-os=linux --cpu=cortex-a8
>> --enable-cross-compile \
>> --cross-prefix=/4.4/prebuilts/gcc/linux-x86/arm/
>> arm-linux-androideabi-4.7/bin/arm-linux-androideabi- \
>> --sysroot=/4.4/prebuilts/ndk/current/platforms/android-18/arch-arm \
>> --enable-gpl --enable-avresample --enable-libx264 \
>> --extra-cflags='-DGNU_SOURCE -fno-builtin-sin -fno-builtin-cos' \
>> --extra-ldflags='-Wl,--fix-cortex-a8,-L/.4.4/external/x264'
> Sorry if this is obvious to you (it isn't to me), why
> are you using --extra-cflags?
> I believe -DGNU_SOURCE is both wrong and unneeded.
> And why --fix-cortex-a8?

 I have tried with --extra-cfags and without.

-DCNU_SOURCE is an ifdef in math.h included in the NDK.

/* BIONIC: GLibc compatibility - required by the ARM toolchain */
#ifdef _GNU_SOURCE
void  sincos(double x, double *sin, double *cos);
void  sincosf(float x, float *sin, float *cos);
void  sincosl(long double x, long double *sin, long double *cos);

> The main reason I ask this is that there may be something
> missing in our configure script (that wasn't reported yet
> or - even worse - the report was missed). In this case it
> would make sense to fix it for all users.

I don't think anything is missing from the configure script. The issue
appears to be a lack of ability to tell if sincos/sincof/sincol is
available. IIUC, that is usually handled by the compiler with
--extra-cflags but it seems in this case the compiler is not able to deal
with them.

--extra-cflags='-DGNU_SOURCE -fno-builtin-sin -fno-builtin-cos'

I don't know if that is because of ffmpeg configuration or because the
compiler is lacking that logic. I have observed that the ffmpeg4android
script is somehow able to bypass the error but running the previous code
snippet manually does not do anything so there seems to be some other
magic going on.

> [...]
>> libavfilter/avf_showcqt.c:332: error: undefined reference to 'sincos'
> Doesn't this mean that your headers (or toolchain) do
> not match your math library?
> The following compiles fine here (no cross-compiling) with
> gcc -lm. If it doesn't work for your cross-compiler, I
> suspect you have to fix it before you can compile FFmpeg.
> #define _GNU_SOURCE
> #include <math.h>
> int main(void)
> {
> double a, b, c;
> sincos(a, &b, &c);
> return b*c;
> }

The sincos/sincosf/sincol functions are not available in the 4.4 android
NDK libm.a. There are various suggestions for ways to get around it during
the build. One person wrote a patch for an older version of the ffmpeg
configure scripts that was deemed unnecessary to include in ffmpeg based
on the same reason you have above.


However, it is not possible to build the complete ffmpeg with x264 enabled
on android 4.4 without getting around the lack of sincos/sincosf/sincosl
in the NDK math.h/libm.a

- I have tried several options for trying to bypass the problem but none
of them are working for me. At this point my options are to figure out how
to rebuild libm.a from the NDK with the functions enabled, figure out the
correct way to build with the bionic libm.a or add the workarounds
directly to ffmpeg.

- I have tried building against bionic libm.a and math.h but that screws
things up with the libraries built against the NDK includes.

- This is code that needs to be dealt with. I don't know why the compiler
wants to use sincos if it is not available in libm.a. It is not being
called by ffmpeg.  I don't know why the cflags don't work to disable it


void sincos(double x, double* p_sin, double* p_cos) {
  *p_sin = sin(x);
  *p_cos = cos(x);

void sincosf(float x, float* p_sinf, float* p_cosf) {
  *p_sinf = sinf(x);
  *p_cosf = cosf(x);

void sincosl(long double x, long double* p_sinl, long double* p_cosl) {
  *p_sinl = sinl(x);
  *p_cosl = cosl(x);

Patrick Shirkey
Boost Hardware Ltd

More information about the ffmpeg-user mailing list