Search code examples
gccffmpegandroid-ndkcross-platformtoolchain

FFmpeg cross compile for Android fails with on C compiler test for x86_64


I am trying to cross compile FFmpeg for Android with NDK r16b I have manged to compile without any issues for all platforms but x86_64.

Here is my compile script

        #!/bin/bash



    function build_one
    {
    ./configure \
    --prefix=$PREFIX \
    --enable-shared \
    --disable-static \
    --enable-pic \
    --enable-small \
    --disable-programs \
    --disable-symver \
    --target-os=android \
    --enable-cross-compile \
    --cross-prefix=$CROSS_PREFIX \
    --extra-cflags="-Os -fpic $ADDI_CFLAGS" \
    --extra-ldflags="$ADDI_LDFLAGS" \
    --sysroot=$TOOLCHAIN/sysroot $ADDITIONAL_CONFIG_FLAG \
    --disable-all --disable-autodetect --disable-network --enable-pthreads \
    --enable-protocol=file --enable-protocol=pipe --enable-protocol=concat \
    --disable-all --disable-autodetect --disable-network --enable-pthreads \
    --enable-avcodec --enable-avformat --enable-swresample --enable-avfilter --enable-filter=aresample \
    --enable-parser=aac --enable-parser=aac_latm --enable-parser=flac --enable-parser=mpegaudio --enable-parser=vorbis \
    --enable-muxer=mp3,wav --enable-encoder=pcm*,libmp3lame --enable-nonfree --enable-gpl \
    --enable-jni --enable-mediacodec --enable-libmp3lame


    make -j4
    make install
    make distclean
    }

    HOME_PATH=/home/nll/Desktop
    CPU=x86_64
    TOOLCHAIN=$HOME_PATH/my_toolchains/x86_64
    CROSS_PREFIX=$TOOLCHAIN/bin/x86_64-linux-android-
    mkdir -p $(pwd)/android/$CPU
    PREFIX=$(pwd)/android/$CPU
    ADDI_CFLAGS="-march=x86-64 -I$INCLUDE_PATH"
    ADDI_LDFLAGS="-shared -L$LIBS_PATH"
    ADDITIONAL_CONFIG_FLAG="--arch=x86_64 --enable-x86asm"
    build_one

Above script fails with

        WARNING: /home/nll/Desktop/my_toolchains/x86_64/bin/x86_64-linux-android-pkg-config not found, library detection may fail.
    mktemp -u XXXXXX
    5ZpQya
    test_ld cc
    test_cc
    BEGIN /tmp/ffconf.KWqViHoN/test.c
        1   int main(void){ return 0; }
    END /tmp/ffconf.KWqViHoN/test.c
    /home/nll/Desktop/my_toolchains/x86_64/bin/x86_64-linux-android-gcc --sysroot=/home/nll/Desktop/my_toolchains/x86_64/sysroot -Os -fpic -march=x86-64 -I -c -o /tmp/ffconf.KWqViHoN/test.o /tmp/ffconf.KWqViHoN/test.c
    /home/nll/Desktop/my_toolchains/x86_64/bin/x86_64-linux-android-gcc -shared -L --sysroot=/home/nll/Desktop/my_toolchains/x86_64/sysroot -o /tmp/ffconf.KWqViHoN/test /tmp/ffconf.KWqViHoN/test.o
    /home/nll/Desktop/my_toolchains/x86_64/bin/../lib/gcc/x86_64-linux-android/4.9.x/../../../../x86_64-linux-android/bin/ld: error: /tmp/ffconf.KWqViHoN/test.o: unsupported ELF file type 2
    collect2: error: ld returned 1 exit status
    C compiler test failed.

So, error is "unsupported ELF file type 2" which means 64 bit. But, I am trying to build 64 bit library anyway.

I do not understand what is the issue here. Can anyone give me some direction?


Solution

  • The first command line contains -I -c. This means that the directory -c is added to the include path, and the command performs a complete link, not just compilation and assembly. The result is an executable, which is an ET_EXEC object (type 2), hence the final error message. (This has got nothing to do with 64-bit binaries.)

    Something went wrong with setting the include path.