I want to compile FFmpeg with clang as it's more faster,but I don't know how to do it in ubuntu. NDk version r16b ,ffmpeg version 4.1.
I did it with gcc. here is my build script,and it works well.
#!/bin/sh
NDK=/home/gjy/ndk/android-ndk-r16b-linux-x86_64/android-ndk-r16b
ANDROID_VERSION=19
TOOLCHAIN_VERSION=4.9
BUILD_PLATFORM=linux-x86_64
ARCH=arm
ANDROID_ARCH_ABI=armeabi
HOST=arm-linux-androideabi
CROSS=arm-linux-androideabi
SYSROOT=${NDK}/platforms/android-${ANDROID_VERSION}/arch-${ARCH}/
PREFIX=$(pwd)/android/${ANDROID_VERSION}/$ANDROID_ARCH_ABI
TOOLCHAIN=${NDK}/toolchains/${HOST}-${TOOLCHAIN_VERSION}/prebuilt/${BUILD_PLATFORM}
CFLAGS="-Os -fpic -march=armv5te -isysroot $NDK/sysroot -I$NDK/sysroot/usr/include/$CROSS -D__ANDROID_API__=$ANDROID_VERSION -U_FILE_OFFSET_BITS"
CROSS_PREFIX=${TOOLCHAIN}/bin/${CROSS}-
build(){
echo "configuring $ANDROID_ARCH_ABI ANDROID_VERSION=$ANDROID_VERSION"
./configure \
--prefix=$PREFIX \
--enable-neon \
--enable-hwaccels \
--enable-gpl \
--enable-postproc \
--enable-shared \
--enable-jni \
--enable-mediacodec \
--enable-decoder=h264_mediacodec \
--enable-hwaccel=h264_mediacodec \
--enable-decoder=hevc_mediacodec \
--enable-decoder=mpeg4_mediacodec \
--enable-decoder=vp8_mediacodec \
--enable-decoder=vp9_mediacodec \
--disable-static \
--disable-doc \
--enable-ffmpeg \
--disable-ffplay \
--disable-ffprobe \
--enable-avdevice \
--disable-doc \
--disable-symver \
--cross-prefix=$CROSS_PREFIX \
--target-os=android \
--arch=$ARCH \
--disable-yasm \
--enable-cross-compile \
--sysroot=$SYSROOT \
--extra-cflags="$CFLAGS " \
--extra-ldflags="$ADDI_LDFLAGS" \
$ADDITIONAL_CONFIGURE_FLAG
make clean
make -j4
make install
echo "$ANDROID_ARCH_ABI installed"
}
build
I wonder how to do it with clang friendly.I'm still new int the NDK and I've just started learning.So I have no idea to do it at all. When I was trying turn to clang,and get many errors. After trying so many times,I update my build script with this question:
#!/bin/sh
#r16b min support android-14 max android-8.1
NDK=/home/gjy/ndk/android-ndk-r16b-linux-x86_64/android-ndk-r16b
ANDROID_VERSION=19
TOOLCHAIN_VERSION=4.9
BUILD_PLATFORM=linux-x86_64
ARCH=arm
ANDROID_ARCH_ABI=armeabi
HOST=arm-linux-androideabi
CROSS=arm-linux-androideabi
SYSROOT=${NDK}/platforms/android-${ANDROID_VERSION}/arch-${ARCH}/
PREFIX=$(pwd)/android/${ANDROID_VERSION}/$ANDROID_ARCH_ABI
TOOLCHAIN=${NDK}/toolchains/llvm/prebuilt/${BUILD_PLATFORM}/bin
#LD
LD=${NDK}/toolchains/${HOST}-${TOOLCHAIN_VERSION}/prebuilt/${BUILD_PLATFORM}/bin/${CROSS}-ld
#AS
AS=${NDK}/toolchains/${HOST}-${TOOLCHAIN_VERSION}/prebuilt/${BUILD_PLATFORM}/bin/${CROSS}-as
#AR
AR=${NDK}/toolchains/${HOST}-${TOOLCHAIN_VERSION}/prebuilt/${BUILD_PLATFORM}/bin/${CROSS}-ar
CFLAGS="-mcpu=$ARCH -I$NDK/sysroot/usr/include/$CROSS -D__ANDROID_API__=$ANDROID_VERSION"
CROSS_PREFIX=${NDK}/toolchains/${HOST}-${TOOLCHAIN_VERSION}/prebuilt/${BUILD_PLATFORM}/bin/${CROSS}-
build(){
echo "configuring $ANDROID_ARCH_ABI ANDROID_VERSION=$ANDROID_VERSION"
./configure \
--prefix=$PREFIX \
--toolchain=clang-usan \
--cross-prefix=$CROSS_PREFIX \
--enable-neon \
--enable-hwaccels \
--enable-gpl \
--enable-postproc \
--enable-shared \
--disable-static \
--enable-jni \
--enable-mediacodec \
--enable-decoder=h264_mediacodec \
--enable-hwaccel=h264_mediacodec \
--enable-decoder=hevc_mediacodec \
--enable-decoder=mpeg4_mediacodec \
--enable-decoder=vp8_mediacodec \
--enable-decoder=vp9_mediacodec \
--disable-doc \
--enable-ffmpeg \
--disable-ffplay \
--disable-ffprobe \
--enable-avdevice \
--disable-doc \
--disable-symver \
--target-os=android \
--extra-ldflags="-shared" \
--arch=$ARCH \
--cpu=$ANDROID_ARCH_ABI \
--extra-cflags="-fPIE -fPIC -ffast-math -funroll-loops -mfloat-abi=softfp -mfpu=vfpv3-d16" \
--enable-x86asm \
--enable-cross-compile \
--cc=$TOOLCHAIN/clang \
--cxx=$TOOLCHAIN/clang++ \
--ld=$LD \
--as=$AS \
--ar=$AR \
--strip=${NDK}/toolchains/${HOST}-${TOOLCHAIN_VERSION}/prebuilt/${BUILD_PLATFORM}/${CROSS}-strip \
$ADDITIONAL_CONFIGURE_FLAG
#make clean
#make -j4
#make install
echo "$ANDROID_ARCH_ABI installed"
}
build
then I get error form config.log :
/home/gjy/ndk/android-ndk-r16b-linux-x86_64/android-ndk-r16b/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-as -D_ISOC99_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_POSIX_C_SOURCE=200112 -D_XOPEN_SOURCE=600 -DPIC -fPIE -fPIC -ffast-math -funroll-loops -mfloat-abi=softfp -mfpu=vfpv3-d16 -mcpu=armeabi -fPIC -c -o /tmp/ffconf.hfTGr6sO/test.o /tmp/ffconf.hfTGr6sO/test.S
/home/gjy/ndk/android-ndk-r16b-linux-x86_64/android-ndk-r16b/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-as: invalid option -- '_'
GNU assembler not found, install/update gas-preprocessor
it seems like that the frist char was ignored. When I try :
/home/gjy/ndk/android-ndk-r16b-linux-x86_64/android-ndk-r16b/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-as -fPIC -c -o /tmp/ffconf.jHtqLsFE/test.o /tmp/ffconf.jHtqLsFE/test.S
invalid option -- P
can any body help fine the problem?
You must add
--as=$TOOLCHAIN/clang
parameter into your configure string for compiling assembler code with clang.