android - 编译 FFMPEG + x264 - undefined reference

标签 android compilation include ffmpeg x264

几天来,我一直试图在网上找到解决方案,但没有成功。我正在使用 Ubuntu 并尝试编译支持 x264 的最新 FFMPEG 稳定版本(1.0.1)。我确保我卸载了任何现有的 x264,然后我下载了最新的 x264 源并使用以下配置对其进行了编译:

./configure --prefix=$PREFIX \
    --enable-shared \
    --enable-static \
    --disable-gpac \
    --extra-cflags=" -I$ARM_INC -fPIC -DANDROID -fpic -mthumb-interwork -ffunction-sections -funwind-tables -fno-short-enums -D__ARM_ARCH_5__ -D__ARM_ARCH_5T__ -D__ARM_ARCH_5E__ -D__ARM_ARCH_5TE__ -Wno-psabi -march=armv5te -msoft-float -mthumb -Os -fomit-frame-pointer -fno-strict-aliasing -finline-limit=64 -DANDROID -Wa,--noexecstack -MMD -MP " \
    --extra-ldflags=" -nostdlib -Bdynamic -Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,nocopyreloc -Wl,-soname,/usr/lib/libz.so -Wl,-rpath-link=$ARM_LIB,-dynamic-linker=/system/bin/linker -L$ARM_LIB -lc -lm -ldl -lgcc" \
    --cross-prefix=${ARM_PRE}- \
    --disable-asm \
    --host=arm-linux \

    make clean
    make install

一切顺利,我检查了安装的版本:
x264 -V
    x264 0.129.x
    built on Dec 27 2012, gcc: 4.6.1
    configuration: --bit-depth=8 --chroma-format=all
    x264 license: GPL version 2 or later

然后我尝试使用以下选项编译 FFMPEG:
./configure --target-os=linux \
    --enable-libx264 \
    --enable-gpl \
    --prefix=$PREFIX \
    --extra-cflags="-I/home/tishu/Workspaces/ffmpeg/ffmpeg/jni/ffmpeg-1.0.1/android/armv7-a/include -I/home/tishu/Workspaces/ffmpeg/ffmpeg/jni/x264 -O3 -fpic -DANDROID -DHAVE_SYS_UIO_H=1 -Dipv6mr_interface=ipv6mr_ifindex -fasm -Wno-psabi -fno-short-enums  -fno-strict-aliasing -finline-limit=300 $OPTIMIZE_CFLAGS " \
    --extra-ldflags="-Wl,-rpath-link=$PLATFORM/usr/lib -L/home/tishu/Workspaces/ffmpeg/ffmpeg/jni/ffmpeg-1.0.1/android/armv7-a/lib -L$PLATFORM/usr/lib -nostdlib -lc -lm -ldl -llog" \
    --enable-cross-compile \
    --extra-libs="-lgcc" \
    --arch=arm \
    --cc=$PREBUILT/bin/arm-linux-androideabi-gcc \
    --cross-prefix=$PREBUILT/bin/arm-linux-androideabi- \
    --nm=$PREBUILT/bin/arm-linux-androideabi-nm \
    --sysroot=$PLATFORM \

configure 和 make clean/make install 运行良好,但是当我尝试创建 .so 文件时,以下命令失败:
/home/tishu/Apps/android-ndk-r8d/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-ld 
    -rpath-link=./android/armv7-a/usr/lib -L/home/tishu/Apps/android-ndk-r8d/platforms/android-14/arch-arm/usr/lib -soname libffmpeg.so -shared -nostdlib  -z,noexecstack -Bsymbolic \
    --whole-archive --no-undefined -o ./android/armv7-a/libffmpeg.so libavcodec/libavcodec.a libavformat/libavformat.a libavutil/libavutil.a libswscale/libswscale.a -lc -lm -lz -ldl -llog  \
    --warn-once \
    --dynamic-linker=/system/bin/linker /home/tishu/Apps/android-ndk-r8d/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/lib/gcc/arm-linux-androideabi/4.4.3/libgcc.a

这失败了,输出如下:
libavcodec/libavcodec.a(libx264.o): In function `X264_frame':
/home/tishu/Workspaces/ffmpeg/ffmpeg/jni/ffmpeg-1.0.1/libavcodec/libx264.c:159: undefined reference to `x264_picture_init'
/home/tishu/Workspaces/ffmpeg/ffmpeg/jni/ffmpeg-1.0.1/libavcodec/libx264.c:179: undefined reference to `x264_encoder_reconfig'
/home/tishu/Workspaces/ffmpeg/ffmpeg/jni/ffmpeg-1.0.1/libavcodec/libx264.c:190: undefined reference to `x264_encoder_encode'
/home/tishu/Workspaces/ffmpeg/ffmpeg/jni/ffmpeg-1.0.1/libavcodec/libx264.c:196: undefined reference to `x264_encoder_delayed_frames'
libavcodec/libavcodec.a(libx264.o): In function `encode_nals':
/home/tishu/Workspaces/ffmpeg/ffmpeg/jni/ffmpeg-1.0.1/libavcodec/libx264.c:101: undefined reference to `x264_bit_depth'
libavcodec/libavcodec.a(libx264.o): In function `X264_close':
/home/tishu/Workspaces/ffmpeg/ffmpeg/jni/ffmpeg-1.0.1/libavcodec/libx264.c:231: undefined reference to `x264_encoder_close'
libavcodec/libavcodec.a(libx264.o): In function `X264_init':
/home/tishu/Workspaces/ffmpeg/ffmpeg/jni/ffmpeg-1.0.1/libavcodec/libx264.c:284: undefined reference to `x264_param_default'
/home/tishu/Workspaces/ffmpeg/ffmpeg/jni/ffmpeg-1.0.1/libavcodec/libx264.c:292: undefined reference to `x264_param_default_preset'
/home/tishu/Workspaces/ffmpeg/ffmpeg/jni/ffmpeg-1.0.1/libavcodec/libx264.c:314: undefined reference to `x264_param_parse'
/home/tishu/Workspaces/ffmpeg/ffmpeg/jni/ffmpeg-1.0.1/libavcodec/libx264.c:459: undefined reference to `x264_param_apply_fastfirstpass'
/home/tishu/Workspaces/ffmpeg/ffmpeg/jni/ffmpeg-1.0.1/libavcodec/libx264.c:490: undefined reference to `x264_param_apply_profile'
/home/tishu/Workspaces/ffmpeg/ffmpeg/jni/ffmpeg-1.0.1/libavcodec/libx264.c:533: undefined reference to `x264_encoder_open_129'
/home/tishu/Workspaces/ffmpeg/ffmpeg/jni/ffmpeg-1.0.1/libavcodec/libx264.c:544: undefined reference to `x264_encoder_headers'

它正在寻找的 x264 版本 (129) 是使用 --eanable-shared 成功安装和编译的版本。显然,当我不包含 libx64 时,所有编译都很好。

问题:如何为最后一个命令指定包含路径?我尝试将路径添加到 $PATH 并将其添加为没有运气的参数:-I/home/tishu/Workspaces/ffmpeg/ffmpeg/jni/x264

谢谢

最佳答案

对于追随者(甚至不是android,而是类似的消息),

/.../mingw-w64-i686/lib/gcc/.../i686-w64-mingw32/bin/ld: 
libavcodec/libavcodec.a(libx264.o):libx264.c:(.text+0x3c): 
undefined reference to `x264_bit_depth'
: undefined reference to `x264_encoder_open_152'

似乎这个常数在 2017 年初被“删除”了,见 https://trac.ffmpeg.org/ticket/6966https://trac.ffmpeg.org/ticket/6932

修复:更新 ffmpeg,或更新 libx264 ......或其他东西......

虽然这些天它应该也支持旧版本的 libx264 ......

关于android - 编译 FFMPEG + x264 - undefined reference ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14082551/

相关文章:

c++ - 在 Linux 上编译外部库

c++ - Codeblocks 编译,GCC 不编译

java - 将常见的 taglibs、js、css 文件移动到一个文件中

c++ - 已在 .obj 中定义 - 没有双重包含

java - Android - 以编程方式通过蓝牙发送图像

android - 在开发 Android 应用程序时,您遇到的错误列表是什么?

Android xml 错误 : "No resource found that matches the given name" with RelativeLayout (@id/LinearLayout_acc, @id/ProgressBar_statusScreen)

c++ - 第一个 CppUnit 测试:对 CppUnit::SourceLine::SourceLine 的 undefined reference

android - 资源分组方式

C++ 不包括来自先前 header 的包含