HarmonyOS鸿蒙Next中ffmpeg编译问题
HarmonyOS鸿蒙Next中ffmpeg编译问题
编译环境:
- 系统:ubuntu 18.04 LTS
- sdk:ohos-sdk-full-3.1.6 -> native-linux-3.1.12.5-Release
- ffmpeg版本:release/4.4 + 少部分自定义需求代码
问题描述: ffmpeg使用静态库方式编译,编译完成生成.o后,再手动使用ld命令将生成的.o链接成单独的动态库(该编译方式是延用ijkplayer依赖的ffmpeg编译方式) 然后ffmpeg的configure正常,make编译生成.a静态库也正常 但是最后一步ld生成so动态库时,提示缺少未定义符号
ld.lld: error: undefined symbol: __divsi3
ld.lld: error: undefined symbol: __udivsi3
ld.lld: error: undefined symbol: __powisf2
ld.lld: error: undefined symbol: __ashrdi3
ld.lld: error: undefined symbol: __divdi3
ld.lld: error: undefined symbol: __modsi3
ld.lld: error: undefined symbol: __ashldi3
ld.lld: error: undefined symbol: __umodsi3
ld.lld: error: undefined symbol: __udivdi3
ld.lld: error: undefined symbol: __lshrdi3
ld.lld: error: undefined symbol: __moddi3
ld.lld: error: undefined symbol: __umoddi3
ld.lld: error: undefined symbol: __floatdidf
ld.lld: error: undefined symbol: __fixunsdfdi
ld.lld: error: undefined symbol: __floatdisf
ld.lld: error: undefined symbol: __fixdfdi
ld.lld: error: undefined symbol: __floatundisf
ld.lld: error: undefined symbol: __fixunssfdi
ld.lld: error: undefined symbol: __floatundidf
ld.lld: error: undefined symbol: __fixsfdi
问题求助: 这些未定义符号,是在harmonyos的ndk哪个库里面提供的 目前使用ld链接.o文件时,将sysroot的lib里面的四个库(libc.a,libm.a,librt.a,libz.so)都链接上了,但还是没找到这些符号的定义
ohos安装位置:/home/dyling/harmonyos/native
对应sysroot,llvm位置:
SYSROOT_PATH:/home/dyling/harmonyos/native/sysroot
LLVM_PATH:/home/dyling/harmonyos/native/llvm
ffmpeg configure参数:
/home/dyling/ffmpeg-ff3.4-r1513_build/harmony/armeabi-v7a/ffmpeg-ff3.4-r1513/configure
--prefix=/home/dyling/ffmpeg-ff3.4-r1513_build/harmony/armeabi-v7a/ffmpeg-ff3.4-r1513/output
--target-os=linux
--arch=armv7-a
--cpu=armv7-a
--sysroot=/home/dyling/harmonyos/native/sysroot
--cc=/home/dyling/harmonyos/native/llvm/bin/clang
--ld=/home/dyling/harmonyos/native/llvm/bin/ld.lld
--ar=/home/dyling/harmonyos/native/llvm/bin/llvm-ar
--nm=/home/dyling/harmonyos/native/llvm/bin/llvm-nm
--ranlib=/home/dyling/harmonyos/native/llvm/bin/llvm-ranlib
--strip=/home/dyling/harmonyos/native/llvm/bin/llvm-strip
--extra-cflags="--verbose -g -O3 -ffast-math -Wall -pipe -fPIC -fcxx-exceptions -fstrict-aliasing -Werror=strict-aliasing -Wa,--noexecstack -DNDEBUG --sysroot=/home/dyling/harmonyos/native/sysroot --target=arm-liteos -march=armv7-a -mfpu=vfpv3-d16 -mfloat-abi=softfp -mthumb -I/home/dyling/harmonyos/native/llvm/include -I/home/dyling/harmonyos/native/sysroot/usr/include -I/home/dyling/harmonyos/native/sysroot/usr/include/arm-linux-ohos -L/home/dyling/harmonyos/native/llvm/lib -L/home/dyling/harmonyos/native/sysroot/usr/lib/arm-linux-ohos"
--extra-cxxflags="--verbose -g -O3 -ffast-math -Wall -pipe -fPIC -fcxx-exceptions -fstrict-aliasing -Werror=strict-aliasing -Wa,--noexecstack -DNDEBUG --sysroot=/home/dyling/harmonyos/native/sysroot -std=c++0x -stdlib=libc++ --target=arm-liteos -march=armv7-a -mfpu=vfpv3-d16 -mfloat-abi=softfp -mthumb -I/home/dyling/harmonyos/native/llvm/include -I/home/dyling/harmonyos/native/sysroot/usr/include -I/home/dyling/harmonyos/native/sysroot/usr/include/arm-linux-ohos -L/home/dyling/harmonyos/native/llvm/lib -L/home/dyling/harmonyos/native/sysroot/usr/lib/arm-linux-ohos"
--extra-ldflags=" -lc -L/home/dyling/harmonyos/native/llvm/lib -L/home/dyling/harmonyos/native/sysroot/usr/lib/arm-linux-ohos" --disable-gpl --disable-nonfree --enable-runtime-cpudetect --disable-gray --disable-swscale-alpha --disable-programs --disable-ffmpeg --disable-ffplay --disable-ffprobe --disable-doc --disable-htmlpages --disable-manpages --disable-podpages --disable-txtpages --disable-avdevice --enable-avcodec --enable-avformat --enable-avutil --enable-swresample --enable-swscale --disable-postproc --enable-avfilter --disable-avresample --enable-network --disable-dxva2 --disable-vaapi --disable-vdpau --disable-encoders --disable-hwaccels --disable-muxers --disable-devices --disable-iconv --enable-protocol=async --enable-cross-compile --disable-linux-perf --enable-pic --enable-optimizations --enable-debug --enable-small --arch=arm --disable-x86asm --enable-neon --enable-thumb --enable-asm --enable-inline-asm
编译命令:
make -j10 && make install
ld链接的系统库libc.a,libm.a,librt.a,libz.so
编译失败详细错误信息:
info, full command: /home/dyling/harmonyos/native/llvm/bin/ld.lld -lm -lz -lrt -shared --sysroot=/home/dyling/harmonyos/native/sysroot --no-undefined -z noexecstack -lc -L/home/dyling/harmonyos/native/llvm/lib -L/home/dyling/harmonyos/native/sysroot/usr/lib/arm-linux-ohos --soname libijkffmpeg.so libavcodec/.o libavfilter/.o libavformat/.o libavutil/.o libswresample/.o libswscale/.o libavcodec/arm/.o libavutil/arm/.o libswresample/arm/.o libswscale/arm/.o -o “/home/dyling/ffmpeg-ff3.4-r1513_build/harmony/armeabi-v7a/ffmpeg-ff3.4-r1513/output/lib/libijkffmpeg.so”
ld.lld: error: undefined symbol: __divsi3
...
ld.lld: error: too many errors emitted, stopping now (use -error-limit=0 to see all errors)
error, make armeabi-v7a libijkffmpeg.so file failed
更多关于HarmonyOS鸿蒙Next中ffmpeg编译问题的实战教程也可以访问 https://www.itying.com/category-93-b0.html
更多关于HarmonyOS鸿蒙Next中ffmpeg编译问题的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html
找到这个系统库了,缺失的函数的实现,是在 `libclang_rt.builtins.a` 这个库里面提供的
LDFLAGS选项添加上对应的`libclang_rt.builtins.a`路径即可

__divsi3 __udivsi3 __powisf2 __ashrdi3 __divdi3 __modsi3 __ashldi3 __umodsi3 __udivdi3 __lshrdi3 __moddi3 __umoddi3 __floatdidf __fixunsdfdi __floatdisf __fixdfdi __floatundisf __fixunssfdi __floatundidf __fixsfdi
网上找了下这些函数的资料,在compiler-rt开源库里面都能找到这些函数的实现,感觉鸿蒙系统库应该也会有相应的系统库才对
如果没有,是不是可以考虑手动使用ohos的ndk编一个,然后编译ffmpeg时,再将这个库链接进去
在HarmonyOS鸿蒙Next中编译FFmpeg时,可能会遇到一些特定的问题。首先,确保你的开发环境已经正确配置了鸿蒙的NDK(Native Development Kit),因为FFmpeg是一个C/C++库,需要NDK进行交叉编译。鸿蒙Next的NDK路径通常位于/path/to/harmonyos/ndk
。
在编译FFmpeg之前,你需要下载FFmpeg的源代码,并解压到你的工作目录。然后,创建一个编译脚本(如build_ffmpeg.sh
),在脚本中指定鸿蒙的NDK路径、目标架构(如arm64-v8a
)、以及FFmpeg的配置选项。以下是一个简单的编译脚本示例:
#!/bin/bash
NDK_PATH=/path/to/harmonyos/ndk
TOOLCHAIN=$NDK_PATH/toolchains/llvm/prebuilt/linux-x86_64
API=21
ARCH=arm64
TARGET=aarch64-linux-android
SYSROOT=$TOOLCHAIN/sysroot
PREFIX=$(pwd)/android/$ARCH
./configure \
--prefix=$PREFIX \
--enable-cross-compile \
--cross-prefix=$TOOLCHAIN/bin/$TARGET$API- \
--sysroot=$SYSROOT \
--arch=$ARCH \
--target-os=android \
--disable-static \
--enable-shared \
--disable-doc \
--disable-ffmpeg \
--disable-ffplay \
--disable-ffprobe \
--disable-symver \
--disable-debug
make -j4
make install
在运行脚本之前,确保你已经安装了必要的依赖项,如make
和pkg-config
。然后,执行脚本进行编译:
chmod +x build_ffmpeg.sh
./build_ffmpeg.sh
编译完成后,生成的库文件将位于android/$ARCH
目录中。你可以将这些库文件集成到你的鸿蒙应用中。
如果在编译过程中遇到错误,检查日志文件以获取更多信息,并根据错误信息调整配置选项或解决依赖问题。
在HarmonyOS鸿蒙Next中编译FFmpeg时,可能会遇到以下问题及解决方法:
-
编译器兼容性:确保使用与HarmonyOS兼容的编译器,如Clang。可以通过设置环境变量
CC=clang
和CXX=clang++
来指定编译器。 -
依赖库缺失:FFmpeg依赖多个库,如libx264、libmp3lame等。确保这些库已正确安装,并在编译时通过
--enable-libx264
等参数启用。 -
平台架构适配:鸿蒙Next可能使用不同的架构(如ARM64)。在配置时使用
--arch=arm64
等参数确保正确适配。 -
配置参数:使用
./configure
命令时,添加--enable-cross-compile
和--target-os=linux
等参数,确保跨平台编译顺利进行。 -
调试信息:编译失败时,查看
config.log
文件,获取详细错误信息,便于排查问题。
通过这些步骤,可以更顺利地在HarmonyOS鸿蒙Next中编译FFmpeg。