HarmonyOS 鸿蒙Next ffmpeg编译鸿蒙版本,arm64编译错误

发布于 1周前 作者 zlyuanteng 来自 鸿蒙OS

HarmonyOS 鸿蒙Next ffmpeg编译鸿蒙版本,arm64编译错误

编译鸿蒙版本的ffmpeg:

发现armv7可以编译成功,arm64在连接阶段编译失败。

ffmpeg版本:4.4.2

armv7的configure命令:

configure   --disable-everything   --disable-programs  --disable-doc   --disable-filters   --disable-avdevice   --disable-postproc   --disable-hwaccels   --disable-bzlib      --disable-videotoolbox
–enable-avresample --enable-pic

     --enable-decoder=aac --enable-decoder=aac_latm --enable-decoder=h264 --enable-decoder=hevc --enable-decoder=mpeg4 --enable-decoder=mp3 --enable-decoder=mp3adu --enable-decoder=mp3float --enable-decoder=mp3on4float --enable-decoder=mp3adufloat --enable-decoder=mp3on4 --enable-decoder=pcm_s16le --enable-decoder=ac3_at --enable-decoder=eac3_at                     --enable-demuxer=flv --enable-demuxer=aac --enable-demuxer=live_flv --enable-demuxer=webvtt --enable-demuxer=srt --enable-demuxer=mov --enable-demuxer=mp3 --enable-demuxer=mpegts --enable-demuxer=matroska --enable-demuxer=h264 --enable-demuxer=ac3 --enable-demuxer=eac3 --enable-demuxer=ass           --enable-muxer=mp4 --enable-muxer=adts --enable-muxer=mpegts             --enable-parser=aac --enable-parser=h264 --enable-parser=hevc --enable-parser=aac_latm --enable-parser=ac3                      --enable-protocol=file --enable-protocol=rtmp --enable-protocol=http --enable-protocol=https           --enable-bsf=aac_adtstoasc --enable-bsf=h264_mp4toannexb --enable-bsf=hevc_mp4toannexb --enable-bsf=extract_extradata               --enable-filter=atempo --enable-filter=aresample --enable-filter=aformat --enable-filter=volume
    --enable-cross-compile         --enable-small         --disable-runtime-cpudetect --target-os=linux --arch=arm --cross-prefix=llvm- --disable-linux-perf --toolchain=hardened --enable-neon --enable-thumb             --as=             --cc=/Users/user/Library/OpenHarmony/Sdk/<span class="hljs-number"><span class="hljs-number">11</span></span>/native/llvm/bin/armv7-unknown-linux-ohos-clang               --ld=/Users/user/Library/OpenHarmony/Sdk/<span class="hljs-number"><span class="hljs-number">11</span></span>/native/llvm/bin/armv7-unknown-linux-ohos-clang               --strip=                --sysroot=/Users/user/Library/OpenHarmony/Sdk/<span class="hljs-number"><span class="hljs-number">11</span></span>/native/sysroot              --extra-cflags=-march=armv7<span class="hljs-operator"><span class="hljs-operator">-a</span></span> -mcpu=cortex<span class="hljs-operator"><span class="hljs-operator">-a</span></span>8 -mfpu=vfpv3<span class="hljs-operator"><span class="hljs-operator">-d</span></span>16 -mfloat-abi=softfp -mthumb -D_FORTIFY_SOURCE=<span class="hljs-number"><span class="hljs-number">2</span></span> -fstack-protector-all                --extra-ldflags=               --prefix=/Users/user/code/harmonyOs/thirdParty/external/install/ffmpeg/HarmonyOS/armeabi-v7a</code><button style="position: absolute; padding: 4px 8px 0px; cursor: pointer; top: 8px; right: 8px; font-size: 14px;">复制</button></pre>  <p>链接命令</p>  <pre style="position: relative;"><code class="language-bash hljs  hljs ">/Users/user/Library/OpenHarmony/Sdk/<span class="hljs-number"><span class="hljs-number">11</span></span>/native/llvm/bin/armv7-unknown-linux-ohos-clang -std=c++<span class="hljs-number"><span class="hljs-number">11</span></span> build_version.cpp -lm -lz -shared --sysroot=/Users/user/Library/OpenHarmony/Sdk/<span class="hljs-number"><span class="hljs-number">11</span></span>/native/sysroot -I/Users/user/code/harmonyOs/thirdParty/external/install/ffmpeg/HarmonyOS/armeabi-v7a/include      -Wl,--no-undefined -Wl,-z,noexecstack -Wl,--fix-cortex<span class="hljs-operator"><span class="hljs-operator">-a</span></span>8   -Wl,-soname,libalivcffmpeg.so      /Users/user/code/harmonyOs/thirdParty/external/build/ffmpeg/HarmonyOS/armeabi-v7a/libavcodec/*o /Users/user/code/harmonyOs/thirdParty/external/build/ffmpeg/HarmonyOS/armeabi-v7a/libavcodec/arm/*.o /Users/user/code/harmonyOs/thirdParty/external/build/ffmpeg/HarmonyOS/armeabi-v7a/libswresample/*o /Users/user/code/harmonyOs/thirdParty/external/build/ffmpeg/HarmonyOS/armeabi-v7a/libswresample/arm/*.o /Users/user/code/harmonyOs/thirdParty/external/build/ffmpeg/HarmonyOS/armeabi-v7a/libavformat/*o /Users/user/code/harmonyOs/thirdParty/external/build/ffmpeg/HarmonyOS/armeabi-v7a/libavutil/*o /Users/user/code/harmonyOs/thirdParty/external/build/ffmpeg/HarmonyOS/armeabi-v7a/libavutil/arm/*.o /Users/user/code/harmonyOs/thirdParty/external/build/ffmpeg/HarmonyOS/armeabi-v7a/libswscale/*o /Users/user/code/harmonyOs/thirdParty/external/build/ffmpeg/HarmonyOS/armeabi-v7a/libswscale/arm/*.o /Users/user/code/harmonyOs/thirdParty/external/build/ffmpeg/HarmonyOS/armeabi-v7a/libavfilter/*o     -o /Users/user/code/harmonyOs/thirdParty/external/install/ffmpeg/HarmonyOS/armeabi-v7a//libalivcffmpeg.so     -Wl,--whole-archive    -lcurl -L/Users/user/code/harmonyOs/thirdParty/external/install/curl/HarmonyOS/armeabi-v7a/lib/ -lssl -lcrypto -L/Users/user/code/harmonyOs/thirdParty/external/install/openssl/HarmonyOS/armeabi-v7a/lib/ -lxml2 -L/Users/user/code/harmonyOs/thirdParty/external/install/libxml2/HarmonyOS/armeabi-v7a/lib/ -lnghttp2 -L/Users/user/code/harmonyOs/thirdParty/external/install/nghttp2/HarmonyOS/armeabi-v7a/lib/ -Wl,--no-whole-archive -Wl,--build-id=sha1

<button style="position: absolute; padding: 4px 8px 0px; cursor: pointer; top: 8px; right: 8px; font-size: 14px;">复制</button>

可以编译成功

cke_10174.png

现在开始编译arm64

config参数如下

configure   --disable-everything   --disable-programs  --disable-doc   --disable-filters   --disable-avdevice   --disable-postproc   --disable-hwaccels   --disable-bzlib      --disable-videotoolbox
–enable-avresample --enable-pic

     --enable-decoder=aac --enable-decoder=aac_latm --enable-decoder=h264 --enable-decoder=hevc --enable-decoder=mpeg4 --enable-decoder=mp3 --enable-decoder=mp3adu --enable-decoder=mp3float --enable-decoder=mp3on4float --enable-decoder=mp3adufloat --enable-decoder=mp3on4 --enable-decoder=pcm_s16le --enable-decoder=ac3_at --enable-decoder=eac3_at                     --enable-demuxer=flv --enable-demuxer=aac --enable-demuxer=live_flv --enable-demuxer=webvtt --enable-demuxer=srt --enable-demuxer=mov --enable-demuxer=mp3 --enable-demuxer=mpegts --enable-demuxer=matroska --enable-demuxer=h264 --enable-demuxer=ac3 --enable-demuxer=eac3 --enable-demuxer=ass           --enable-muxer=mp4 --enable-muxer=adts --enable-muxer=mpegts             --enable-parser=aac --enable-parser=h264 --enable-parser=hevc --enable-parser=aac_latm --enable-parser=ac3                      --enable-protocol=file --enable-protocol=rtmp --enable-protocol=http --enable-protocol=https           --enable-bsf=aac_adtstoasc --enable-bsf=h264_mp4toannexb --enable-bsf=hevc_mp4toannexb --enable-bsf=extract_extradata               --enable-filter=atempo --enable-filter=aresample --enable-filter=aformat --enable-filter=volume
    --enable-cross-compile         --enable-small         --disable-runtime-cpudetect --target-os=linux --arch=aarch64 --cross-prefix=llvm- --disable-linux-perf --toolchain=hardened --enable-neon --enable-thumb             --as=             --cc=/Users/user/Library/OpenHarmony/Sdk/<span class="hljs-number"><span class="hljs-number">11</span></span>/native/llvm/bin/aarch64-unknown-linux-ohos-clang               --ld=/Users/user/Library/OpenHarmony/Sdk/<span class="hljs-number"><span class="hljs-number">11</span></span>/native/llvm/bin/aarch64-unknown-linux-ohos-clang               --strip=                --sysroot=/Users/user/Library/OpenHarmony/Sdk/<span class="hljs-number"><span class="hljs-number">11</span></span>/native/sysroot              --extra-cflags=-D_FORTIFY_SOURCE=<span class="hljs-number"><span class="hljs-number">2</span></span> -fstack-protector-all                --extra-ldflags=               --prefix=/Users/user/code/harmonyOs/thirdParty/external/install/ffmpeg/HarmonyOS/arm64-v8a</code><button style="position: absolute; padding: 4px 8px 0px; cursor: pointer; top: 8px; right: 8px; font-size: 14px;">复制</button></pre>  <p>链接命令</p>  <pre style="position: relative;"><code class="language-bash hljs  hljs ">/Users/user/Library/OpenHarmony/Sdk/<span class="hljs-number"><span class="hljs-number">11</span></span>/native/llvm/bin/aarch64-unknown-linux-ohos-clang -std=c++<span class="hljs-number"><span class="hljs-number">11</span></span> build_version.cpp -lm -lz -shared --sysroot=/Users/user/Library/OpenHarmony/Sdk/<span class="hljs-number"><span class="hljs-number">11</span></span>/native/sysroot -I/Users/user/code/harmonyOs/YspCorePlayerHarmonyOS/thirdParty/external/install/ffmpeg/HarmonyOS/arm64-v8a/include      -Wl,--no-undefined -Wl,-z,noexecstack    -Wl,-soname,libalivcffmpeg.so      /Users/user/code/harmonyOs/thirdParty/external/build/ffmpeg/HarmonyOS/arm64-v8a/libavcodec/*o /Users/user/code/harmonyOs/thirdParty/external/build/ffmpeg/HarmonyOS/arm64-v8a/libavcodec/aarch64/*.o /Users/user/code/harmonyOs/thirdParty/external/build/ffmpeg/HarmonyOS/arm64-v8a/libavcodec/neon/*.o /Users/user/code/harmonyOs/thirdParty/external/build/ffmpeg/HarmonyOS/arm64-v8a/libswresample/*o /Users/user/code/harmonyOs/thirdParty/external/build/ffmpeg/HarmonyOS/arm64-v8a/libswresample/aarch64/*.o /Users/user/code/harmonyOs/thirdParty/external/build/ffmpeg/HarmonyOS/arm64-v8a/libavformat/*o /Users/user/code/harmonyOs/thirdParty/external/build/ffmpeg/HarmonyOS/arm64-v8a/libavutil/*o /Users/user/code/harmonyOs/thirdParty/external/build/ffmpeg/HarmonyOS/arm64-v8a/libavutil/aarch64/*.o /Users/user/code/harmonyOs/thirdParty/external/build/ffmpeg/HarmonyOS/arm64-v8a/libswscale/*o /Users/user/code/harmonyOs/thirdParty/external/build/ffmpeg/HarmonyOS/arm64-v8a/libswscale/aarch64/*.o /Users/user/code/harmonyOs/thirdParty/external/build/ffmpeg/HarmonyOS/arm64-v8a/libavfilter/*o     -o /Users/user/code/harmonyOs/thirdParty/external/install/ffmpeg/HarmonyOS/arm64-v8a//libalivcffmpeg.so     -Wl,--whole-archive    -lcurl -L/Users/user/code/harmonyOs/thirdParty/external/install/curl/HarmonyOS/arm64-v8a/lib/ -lssl -lcrypto -L/Users/user/code/harmonyOs/thirdParty/external/install/openssl/HarmonyOS/arm64-v8a/lib/ -lxml2 -L/Users/user/code/harmonyOs/thirdParty/external/install/libxml2/HarmonyOS/arm64-v8a/lib/ -lnghttp2 -L/Users/user/code/harmonyOs/thirdParty/external/install/nghttp2/HarmonyOS/arm64-v8a/lib/ -Wl,--no-whole-archive -Wl,--build-id=sha1</code><button style="position: absolute; padding: 4px 8px 0px; cursor: pointer; top: 8px; right: 8px; font-size: 14px;">复制</button></pre>  <p>发现报错</p>  <pre style="position: relative;"><code class="language-bash hljs  hljs ">ld.lld: error: relocation R_AARCH64_ADR_PREL_PG_HI21 cannot be used against symbol <span class="hljs-string"><span class="hljs-string">'ff_cos_32'</span></span>; recompile with <span class="hljs-operator"><span class="hljs-operator">-f</span></span>PIC

>>> defined in /Users/user/code/harmonyOs/thirdParty/external/build/ffmpeg/HarmonyOS/arm64-v8a/libavcodec/fft_float.o >>> referenced by fft_neon.S:356 (/Users/user/code/harmonyOs/thirdParty/external/build/ffmpeg/HarmonyOS/arm64-v8a/src/libavcodec/aarch64/fft_neon.S:356) >>> /Users/user/code/harmonyOs/thirdParty/external/build/ffmpeg/HarmonyOS/arm64-v8a/libavcodec/aarch64/fft_neon.o:(fft32_neon)

ld.lld: error: relocation R_AARCH64_ADD_ABS_LO12_NC cannot be used against symbol ‘ff_cos_32’; recompile with -fPIC >>> defined in /Users/user/code/harmonyOs/thirdParty/external/build/ffmpeg/HarmonyOS/arm64-v8a/libavcodec/fft_float.o >>> referenced by fft_neon.S:356 (/Users/user/code/harmonyOs/YspCorePlayerHarmonyOS/thirdParty/external/build/ffmpeg/HarmonyOS/arm64-v8a/src/libavcodec/aarch64/fft_neon.S:356) >>> /Users/user/code/harmonyOs/thirdParty/external/build/ffmpeg/HarmonyOS/arm64-v8a/libavcodec/aarch64/fft_neon.o:(fft32_neon)

ld.lld: error: relocation R_AARCH64_ADR_PREL_PG_HI21 cannot be used against symbol ‘ff_cos_64’; recompile with -fPIC >>> defined in /Users/user/code/harmonyOs/thirdParty/external/build/ffmpeg/HarmonyOS/arm64-v8a/libavcodec/fft_float.o >>> referenced by fft_neon.S:357 (/Users/user/code/harmonyOs/thirdParty/external/build/ffmpeg/HarmonyOS/arm64-v8a/src/libavcodec/aarch64/fft_neon.S:357) >>> /Users/user/code/harmonyOs/thirdParty/external/build/ffmpeg/HarmonyOS/arm64-v8a/libavcodec/aarch64/fft_neon.o:(fft64_neon)

ld.lld: error: relocation R_AARCH64_ADD_ABS_LO12_NC cannot be used against symbol ‘ff_cos_64’; recompile with -fPIC >>> defined in /Users/user/code/harmonyOs/thirdParty/external/build/ffmpeg/HarmonyOS/arm64-v8a/libavcodec/fft_float.o >>> referenced by fft_neon.S:357 <button style="position: absolute; padding: 4px 8px 0px; cursor: pointer; top: 8px; right: 8px; font-size: 14px;">复制</button>

通过查询ffmepg的编译选项发现

–enable-pic就可以生成无关的代码

cke_51849.png

这个问题该如何解决呢?

6 回复

问题已经解决

在连接命令上加上

-Wl,-Bsymbolic

找HarmonyOS工作还需要会Flutter的哦,有需要Flutter教程的可以学学大地老师的教程,很不错,B站免费学的哦:https://www.bilibili.com/video/BV1S4411E7LY/?p=17

求so库,可以提供一下吗?

提供的工具打的静态库,我需要动态库

针对HarmonyOS(鸿蒙)下ffmpeg的arm64编译错误,首先确保你的编译环境(如NDK版本、GCC版本)与HarmonyOS开发要求兼容。检查ffmpeg的configure脚本或CMakeLists.txt文件中的配置,确保启用了对arm64的支持,并且所有的依赖库都已正确配置为支持arm64。

此外,查看编译错误日志,识别是哪些文件或模块导致的错误,并检查相关的源码或配置是否有特定于arm64的编译问题。可能需要调整编译选项或修改源码以适应HarmonyOS的API变化。

如果问题依旧没法解决请加我微信,我的微信是itying888。

回到顶部