title: Building ffmpeg for Android with clang
body: <p>I'm trying to build ffmpeg for Android using Clang and Android NDK 20 in Ubuntu 18.04. </p>
  
  <p>I'm trying:</p>
  
  <pre><code>./configure
  --prefix=android/
  --disable-asm
  --enable-cross-compile
  --disable-static
  --disable-programs
  --disable-doc
  --enable-shared
  --enable-protocol=file
  --enable-pic
  --enable-small
  --disable-pthreads
  --ar=/home/sources/android-ndk-r20/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/bin/aarch64-linux-android-ar
  --strip=/home/sources/android-ndk-r20/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/bin/aarch64-linux-android-strip
  --ld=/home/sources/android-ndk-r20/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/bin/aarch64-linux-android-ld
  --cc=/home/sources/android-ndk-r20/toolchains/llvm/prebuilt/linux-x86_64/bin/clang
  --cxx=/home/sources/android-ndk-r20/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++
  --as=/home/sources/android-ndk-r20/toolchains/llvm/prebuilt/linux-x86_64/bin/clang
  --target-os=android
  --extra-cflags=-target aarch64-none-linux-android
  -mfpu=neon
  -mfloat-abi=soft
  -I/home/sources/android-ndk-r20/sysroot/usr/include/aarch64-linux-android
  -O3
  -fPIC
  --extra-ldflags=-L/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/lib/gcc/aarch64-linux-android/4.9.x
  -L/platforms/android-/arch-arm64/usr/lib
  --sysroot=/home/sources/android-ndk-r20/sysroot
  </code></pre>
  
  <p>But I'm getting some compile errors like this:</p>
  
  <pre><code>/home/sources/android-ndk-r20/sysroot/usr/include/stdlib.h:61:7: error: expected identifier or '('
  char* getenv(const char* __name);
        ^
  ./config.h:17:19: note: expanded from macro 'getenv'
  #define getenv(x) NULL
                    ^
  /home/sources/android-ndk-r20/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/8.0.7/include/stddef.h:105:18: note: expanded from macro 'NULL'
  #  define NULL ((void*)0)
                   ^
  In file included from libavdevice/alldevices.c:23:
  In file included from ./libavformat/internal.h:27:
  In file included from ./libavformat/avformat.h:319:
  In file included from ./libavcodec/avcodec.h:31:
  In file included from ./libavutil/samplefmt.h:24:
  In file included from ./libavutil/avutil.h:296:
  In file included from ./libavutil/common.h:39:
  /home/sources/android-ndk-r20/sysroot/usr/include/stdlib.h:61:7: error: expected ')'
  ./config.h:17:19: note: expanded from macro 'getenv'
  #define getenv(x) NULL
                    ^
  /home/sources/android-ndk-r20/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/8.0.7/include/stddef.h:105:18: note: expanded from macro 'NULL'
  #  define NULL ((void*)0)
                   ^
  /home/sources/android-ndk-r20/sysroot/usr/include/stdlib.h:61:7: note: to match this '('
  ./config.h:17:19: note: expanded from macro 'getenv'
  #define getenv(x) NULL
                    ^
  /home/sources/android-ndk-r20/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/8.0.7/include/stddef.h:105:17: note: expanded from macro 'NULL'
  #  define NULL ((void*)0)
                  ^
  In file included from libavdevice/alldevices.c:23:
  In file included from ./libavformat/internal.h:27:
  In file included from ./libavformat/avformat.h:319:
  In file included from ./libavcodec/avcodec.h:31:
  In file included from ./libavutil/samplefmt.h:24:
  In file included from ./libavutil/avutil.h:296:
  In file included from ./libavutil/common.h:39:
  /home/sources/android-ndk-r20/sysroot/usr/include/stdlib.h:61:7: error: expected ')'
  char* getenv(const char* __name);
        ^
  ./config.h:17:19: note: expanded from macro 'getenv'
  #define getenv(x) NULL
                    ^
  /home/sources/android-ndk-r20/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/8.0.7/include/stddef.h:105:24: note: expanded from macro 'NULL'
  #  define NULL ((void*)0)
                         ^
  /home/sources/android-ndk-r20/sysroot/usr/include/stdlib.h:61:7: note: to match this '('
  ./config.h:17:19: note: expanded from macro 'getenv'
  #define getenv(x) NULL
                    ^
  /home/sources/android-ndk-r20/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/8.0.7/include/stddef.h:105:16: note: expanded from macro 'NULL'
  #  define NULL ((void*)0)
                 ^
  In file included from libavdevice/fbdev_dec.c:37:
  In file included from ./libavutil/internal.h:42:
  In file included from ./libavutil/timer.h:41:
  /home/sources/android-ndk-r20/sysroot/usr/include/stdlib.h:61:7: error: expected identifier or '('
  char* getenv(const char* __name);
        ^
  ./config.h:17:19: note: expanded from macro 'getenv'
  #define getenv(x) NULL
                    ^
  /home/sources/android-ndk-r20/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/8.0.7/include/stddef.h:105:18: note: expanded from macro 'NULL'
  #  define NULL ((void*)0)
                   ^
  In file included from libavdevice/fbdev_dec.c:37:
  In file included from ./libavutil/internal.h:42:
  In file included from ./libavutil/timer.h:41:
  /home/sources/android-ndk-r20/sysroot/usr/include/stdlib.h:61:7: error: expected ')'
  ./config.h:17:19: note: expanded from macro 'getenv'
  #define getenv(x) NULL
                    ^
  /home/sources/android-ndk-r20/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/8.0.7/include/stddef.h:105:18: note: expanded from macro 'NULL'
  #  define NULL ((void*)0)
                   ^
  /home/sources/android-ndk-r20/sysroot/usr/include/stdlib.h:61:7: note: to match this '('
  ./config.h:17:19: note: expanded from macro 'getenv'
  #define getenv(x) NULL
  </code></pre>
  
  <p>I also tried, from <a href="https://stackoverflow.com/questions/54339191/how-to-compile-ffmpeg-for-android-with-clang-in-ubuntu18-04">here</a>:</p>
  
  <pre><code>./configure
  --prefix=/home/deps/build/ffmpeg/arm64
  --cross-prefix=/home/sources/android-ndk-r20/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/aarch64-linux-android-
  --sysroot=/home/sources/android-ndk-r20/sysroot
  --disable-static
  --disable-doc
  --disable-ffmpeg
  --disable-ffplay
  --disable-ffprobe
  --disable-symver
  --enable-shared
  --enable-protocol=concat
  --enable-protocol=file
  --enable-muxer=mp4
  --enable-demuxer=mpegts
  --target-os=android
  --enable-decoder=h264
  --enable-cross-compile
  --arch=aarch64
  --toolchain=clang-usan
  --extra-cflags=-fPIE
  -fPIC
  -ffast-math
  -funroll-loops
  -mfloat-abi=softfp
  -mfpu=vfpv3-d16
  --extra-ldflags=-pie
  --ar=/home/sources/android-ndk-r20/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/bin/aarch64-linux-android-ar
  --strip=/home/sources/android-ndk-r20/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/bin/aarch64-linux-android-strip
  --ld=/home/sources/android-ndk-r20/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/bin/aarch64-linux-android-ld
  --cc=/home/sources/android-ndk-r20/toolchains/llvm/prebuilt/linux-x86_64/bin/clang
  --cxx=/home/sources/android-ndk-r20/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++
  --as=/home/sources/android-ndk-r20/toolchains/llvm/prebuilt/linux-x86_64/bin/clang
  </code></pre>
  
  <p>But I get this error:</p>
  
  <pre><code>/home/sources/android-ndk-r20/toolchains/llvm/prebuilt/linux-x86_64/bin/clang is unable to create an executable file.
  C compiler test failed.
  </code></pre>
  
  <p>In the log file I get:</p>
  
  <pre><code>/home/sources/android-ndk-r20/toolchains/llvm/prebuilt/linux-x86_64/bin/clang --sysroot=/home/sources/android-ndk-r20/sysroot -fsanitize=undefined -fPIE -fPIC -ffast-math -funroll-loops -mfloat-abi=softfp -mfpu=vfpv3-d16 -c -o /tmp/ffconf.knsd57OI/test.o /tmp/ffconf.knsd57OI/test.c
  clang: warning: argument unused during compilation: '-mfloat-abi=softfp' [-Wunused-command-line-argument]
  clang: warning: argument unused during compilation: '-mfpu=vfpv3-d16' [-Wunused-command-line-argument]
  /home/sources/android-ndk-r20/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/bin/aarch64-linux-android-ld -pie -fsanitize=undefined --sysroot=/home/sources/android-ndk-r20/sysroot -o /tmp/ffconf.knsd57OI/test /tmp/ffconf.knsd57OI/test.o
  /home/sources/android-ndk-r20/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/bin/aarch64-linux-android-ld: -f may not be used without -shared
  C compiler test failed.
  </code></pre>
  
  <p>It looks like, by the line <code>-fsanitize=undefined</code> that an undefined is being passed, I don't know why.</p>
  
  <p>Anyone knows what's happening or an alternative way to build?</p>