我正在尝试为Android编译FFMpeg而我在Android 4上运行APK时遇到了麻烦(在Android 5上我没有得到这个糟糕的不满意链接错误):
05-09 15:16:18.880 22160-22304/com.gpac.Osmo4 I/LibrariesLoader﹕ Loading library avcodec...
05-09 15:16:18.910 22160-22304/com.gpac.Osmo4 E/dalvikvm﹕ dlopen("/data/app-lib/com.gpac.Osmo4-1/libavcodec.so") failed: Cannot load library: soinfo_relocate(linker.cpp:975): cannot locate symbol "log2f" referenced by "libavcodec.so"...
05-09 15:16:18.920 22160-22304/com.gpac.Osmo4 E/LibrariesLoader﹕ Failed to load library : avcodec due to link error Cannot load library: soinfo_relocate(linker.cpp:975): cannot locate symbol "log2f" referenced by "libavcodec.so"...
java.lang.UnsatisfiedLinkError: Cannot load library: soinfo_relocate(linker.cpp:975): cannot locate symbol "log2f" referenced by "libavcodec.so"...
我使用的是NDK 10d,工具链4.9但我也尝试使用NDK 8和9而且我得到了相同的结果。 使用较旧的NDK版本编译时唯一的区别是我收到一条警告消息:
incompatible declaration of built-in function log2f
我检查了目标设备上的libm.so(其中log2f应该是),当然没有定义log2f函数,但是用手替换库可能会导致其他一些东西崩溃+我需要根电话。
我知道这是一个链接器问题,它不应该那么难修复,但我没有想法。
编辑:
我正在尝试编译ffmpeg 2.4.3
我用来配置的脚本:
#!/bin/bash
if [ "$NDK" = "" ]; then
echo NDK variable not set, assuming ${HOME}/android-ndk
export NDK=${HOME}/android-ndk
fi
echo "Compiling with NDK located at: $NDK"
ROOT_DIR=`cd ..; pwd`
CUR_DIR=`pwd`
echo "Fetching Android system headers"
if [ ! -d "$ROOT_DIR/android-source/frameworks/base" ]; then
git clone --depth=1 --branch cm-11.0 https://github.com/CyanogenMod/android_frameworks_base.git "$ROOT_DIR/android-source/frameworks/base"
fi
if [ ! -d "$ROOT_DIR/android-source/system/core" ]; then
git clone --depth=1 --branch cm-11.0 https://github.com/CyanogenMod/android_system_core.git "$ROOT_DIR/android-source/system/core"
fi
if [ ! -d "$ROOT_DIR/android-source/frameworks/av" ]; then
git clone --depth=1 --branch cm-11.0 https://github.com/CyanogenMod/android_frameworks_av "$ROOT_DIR/android-source/frameworks/av"
fi
if [ ! -d "$ROOT_DIR/android-source/hardware/libhardware" ]; then
git clone --depth=1 --branch cm-11.0 https://github.com/CyanogenMod/android_hardware_libhardware.git "$ROOT_DIR/android-source/hardware/libhardware"
fi
if [ ! -d "$ROOT_DIR/android-source/frameworks/native" ]; then
git clone --depth=1 --branch cm-11.0 https://github.com/CyanogenMod/android_frameworks_native.git "$ROOT_DIR/android-source/frameworks/native"
fi
echo "Fetching Android libraries for linking"
# Libraries from any froyo/gingerbread device/emulator should work
# fine, since the symbols used should be available on most of them.
if [ ! -d "$ROOT_DIR/android-libs" ]; then
wget http://download.cyanogenmod.org/get/jenkins/65493/cm-10.2.1.3-serranoltexx.zip -P../
unzip ../cm-10.2.1.3-serranoltexx.zip system/lib/* -d../
mv ../system/lib "$ROOT_DIR/android-libs"
rmdir ../system
rm ../cm-10.2.1.3-serranoltexx.zip
fi
ANDROID_SOURCE="$ROOT_DIR/android-source"
echo "ANDROID_SOURCE: $ANDROID_SOURCE"
ANDROID_LIBS="$ROOT_DIR/android-libs"
OBJS="$ROOT_DIR/objs"
if [ "$DEST" = "" ]; then
rm -rf $ROOT_DIR/build/stagefright
mkdir -p $ROOT_DIR/build/stagefright
DEST=$ROOT_DIR/build/stagefright
fi
#for ABI in "armeabi-v7a" "armeabi" "x86"; do
for ABI in "armeabi-v7a" "armeabi"; do
if [ "$ABI" = "x86" ]; then
ARCH="x86"
TOOLCHAIN=`echo $NDK/toolchains/x86-4.9/prebuilt/*-x86*`
else
ARCH="arm"
TOOLCHAIN=`echo $NDK/toolchains/arm-linux-androideabi-4.9/prebuilt/*-x86*`
fi
SYSROOT=$NDK/platforms/android-18/arch-$ARCH
# Expand the prebuilt/* path into the correct one
export PATH=$TOOLCHAIN/bin:$PATH
FLAGS="--target-os=linux --arch=$ARCH"
FLAGS="$FLAGS --sysroot=$SYSROOT"
FLAGS="$FLAGS --enable-shared --disable-doc --disable-ffplay --disable-ffprobe --disable-ffserver --disable-symver"
if [ "$ARCH" = "arm" ]; then
FLAGS="$FLAGS --cross-prefix=$TOOLCHAIN/bin/arm-linux-androideabi- --cpu=armv7-a --enable-libstagefright-h264"
#FLAGS="$FLAGS --cross-prefix=$TOOLCHAIN/bin/arm-linux-androideabi- --cpu=armv7-a"
else
FLAGS="$FLAGS --cross-prefix=$TOOLCHAIN/bin/i686-linux-android- --disable-asm"
fi
EXTRA_CFLAGS="-I$DEST/$ABI/include"
EXTRA_CFLAGS="$EXTRA_CFLAGS -I$ANDROID_SOURCE/frameworks/base/include -I$ANDROID_SOURCE/system/core/include"
EXTRA_CFLAGS="$EXTRA_CFLAGS -I$ANDROID_SOURCE/frameworks/native/include"
EXTRA_CFLAGS="$EXTRA_CFLAGS -I$ANDROID_SOURCE/frameworks/native/include/media/openmax"
EXTRA_CFLAGS="$EXTRA_CFLAGS -I$ANDROID_SOURCE/frameworks/av/include"
EXTRA_CFLAGS="$EXTRA_CFLAGS -I$ANDROID_SOURCE/frameworks/av/media/libstagefright"
EXTRA_CFLAGS="$EXTRA_CFLAGS -I$NDK/sources/cxx-stl/gnu-libstdc++/4.9/include -I$NDK/sources/cxx-stl/gnu-libstdc++/4.9/libs/$ABI/include"
EXTRA_CFLAGS="$EXTRA_CFLAGS -I$ANDROID_SOURCE/hardware/libhardware/include"
if [ "$ARCH" = "arm" ]; then
EXTRA_CFLAGS="$EXTRA_CFLAGS -march=armv7-a -mfloat-abi=softfp -mfpu=neon -Wl,--no-undefined" #-Werror=implicit-function-declaration"
fi
EXTRA_LDFLAGS="-Wl,--fix-cortex-a8 -L$ANDROID_LIBS -Wl,-rpath-link,$ANDROID_LIBS -L$NDK/sources/cxx-stl/gnu-libstdc++/4.9/libs/$ABI"
EXTRA_CXXFLAGS="-Wno-multichar -fno-exceptions -fno-rtti"
FLAGS="$FLAGS --prefix=$DEST/$ABI"
mkdir -p $DEST/$ABI
mkdir -p $OBJS/$ABI
echo $FLAGS --extra-cflags="$EXTRA_CFLAGS" --extra-ldflags="$EXTRA_LDFLAGS" --extra-cxxflags="$EXTRA_CXXFLAGS" > $DEST/$ABI/info.txt
echo "Configuring ..."
cd $OBJS/$ABI
$ROOT_DIR/configure $FLAGS --extra-cflags="$EXTRA_CFLAGS" --extra-ldflags="$EXTRA_LDFLAGS" --extra-cxxflags="$EXTRA_CXXFLAGS" | tee $DEST/$ABI/configuration.txt
[ $PIPESTATUS == 0 ] || exit 1
echo "Making ..."
#make clean
make -j4 || exit 1
make install || exit 1
cd $CUR_DIR
done
答案 0 :(得分:0)
你可以使用最新的NDK,只设置android-19的平台而不是最新的android-21。
您使用了某些cyanogenmod build中的库,这些库太好了#34;例如,您从libm.so
获得log2()
。相反,您需要在支持的设备上使用libm.so
版本的最小公分母。你不需要寻找这样的图书馆;你有#34;官员" NDK中的版本。
我知道要启用硬件编解码器,你需要一些"非官方的"库。但是要小心,将包含下载的库的目录放在查找列表的末尾。或者更安全,只复制你的链接真正需要的几个库(如libcutils.so
)。