1 添加方式
./configure
中通过--extra-cflags
指定库头文件路径,通过--extra-ldflags
指定链接库路径,形式如下:
./configure --extra-cflags="-I/path/to/my/lib/include" --extra-ldflags="-L/path/to/my/lib/lib" ...
如需明确指定可采用--extra-ldflags="-L/path/to/my/lib/lib -llibxxx.so /path/to/my/lib/lib/libxxx.a"
的形式
2 可能问题
undefined reference to
__gxx_personality_v0
问题原因: 未包含C++库(ffmpeg默认gcc编译)
解决方法:--extra-ldflags
中添加-lstdc++
,若仍存在,可以考虑使用$NDK_PATH/sources/cxx-stl/gnu-libstdc++/4.9/libs/$ANDROID_ARCH_ABI/libgnustl_shared.so
或-l$NDK_PATH/sources/cxx-stl/gnu-libstdc++/4.9/libs/$ANDROID_ARCH_ABI/libgnustl_static.a
sys/sysctl.h: no such files or dictionary
问题原因:为了解决前一问题使用了-share
参数,冲突
解决办法:去掉该参数,使用libgnustl_shared.so
。[ aaccodec / hevc_mvs ] error: expected identifier or '(' before numeric constant int B0 = 0...
问题原因:ffmpeg与ndk中B0
重定义了
解决方法:直接将报错文件中B0
全部替换,如:BX0
[ hevc_mvs ] error: 'y0000000' undeclared
问题原因:前一问题只修改了报错部分,没替换全
3 最终脚本范例
外部依赖以libavs2
为例,最终一步是打包成.so
文件
#!/bin/sh
# For arm64, install libc6-dev-i386 first.
build_dir=$(pwd)
AVS2SRC=$build_dir/ffmpeg_avs2_lib
PREFIX=$build_dir/ffmpeg_avs2_lib
ARCH=arm64
SDK_VERSION=24 # only SDK>=21 support arm64
FFMPEG_SRC=FFmpegAVS2
NDK="/home/rew/Android/android-ndk-r14b"
export PKG_CONFIG_PATH=/home/rew/Rew/AVS2/cavs2dec_hwren/build/linux/android/arm/lib/pkgconfig
if [ "$ARCH" = "arm64" ]
then
PLATFORM_PREFIX="aarch64-linux-android"
HOST="aarch64"
PLATFORM_VERSION=4.9
ABI="arm64-v8a"
EXTRA_CFLAGS="-march=armv8-a -O3 -D__ARM_ARCH_7__ -D__ARM_ARCH_7A__ -DPIC \
-flax-vector-conversions -Wunused-variable -fPIE -pie"
else
PLATFORM_PREFIX="arm-linux-androideabi"
HOST="arm"
PLATFORM_VERSION=4.9
ABI="armeabi-v7a"
EXTRA_CFLAGS="-march=armv7-a -mfloat-abi=softfp -mfpu=neon -marm -mtune=cortex-a8 -fPIE -pie \
-D__ARM_ARCH_7__ -D__ARM_ARCH_7A__ -flax-vector-conversions -Wunused-variable"
fi
NDKROOT=$NDK/platforms/android-${SDK_VERSION}/arch-${ARCH}
TOOLCHAIN=$NDK/toolchains/${PLATFORM_PREFIX}-${PLATFORM_VERSION}/prebuilt/linux-x86_64
CROSS_PREFIX=$TOOLCHAIN/bin/${PLATFORM_PREFIX}-
EXTRA_LDFLAGS="-fPIE -pie -llog -landroid $NDK/sources/cxx-stl/gnu-libstdc++/4.9/libs/$ABI/libgnustl_shared.so"
build_one(){
./configure \
--target-os=linux \
--prefix=$PREFIX \
--enable-cross-compile \
--extra-libs="-lgcc" \
--arch=$ARCH \
--cross-prefix=$CROSS_PREFIX \
--cc=${CROSS_PREFIX}gcc \
--nm=${CROSS_PREFIX}nm \
--sysroot=$NDKROOT \
--extra-cflags="-I$NDKROOT/usr/include -I$AVS2SRC/include -O3 -fpic \
-DANDROID -DHAVE_SYS_UIO_H=1 -Dipv6mr_interface=ipv6mr_ifindex -fasm \
-Wno-psabi -fno-short-enums -fno-strict-aliasing -finline-limit=300 \
$EXTRA_CFLAGS" \
--extra-ldflags="-Wl,-rpath-link=$NDKROOT/usr/lib -L$NDKROOT/usr/lib -lc \
-lm -ldl -llog -lstdc++ $AVS2SRC/lib/libdavs2.a -L$AVS2SRC/lib -ldavs2 \
$EXTRA_LDFLAGS" \
--enable-gpl \
--enable-libdavs2 \
--enable-neon \
--enable-asm \
--disable-shared \
--enable-static \
--disable-debug \
--disable-linux-perf \
--pkg-config=/usr/bin/pkg-config
}
cd $FFMPEG_SRC
make distclean
build_one || exit 1
(make -j16 && make install) || exit 1
${CROSS_PREFIX}ld -z muldefs -rpath-link=$NDKROOT/usr/lib \
-L$NDKROOT/usr/lib -L$PREFIX/lib -soname libffmpeg.so -shared -nostdlib -Bsymbolic \
--whole-archive --no-undefined -o $PREFIX/libffmpeg.so $AVS2SRC/lib/libdavs2.a \
libavcodec/libavcodec.a libavfilter/libavfilter.a libswresample/libswresample.a \
libavformat/libavformat.a libavutil/libavutil.a libswscale/libswscale.a \
libpostproc/libpostproc.a libavdevice/libavdevice.a -fPIC -lc -lm -lz -ldl -llog \
$NDK/sources/cxx-stl/gnu-libstdc++/4.9/libs/$ABI/libgnustl_shared.so -lstdc++ \
--dynamic-linker=/system/bin/linker $TOOLCHAIN/lib/gcc/$PLATFORM_PREFIX/4.9.x/libgcc.a