提问人:Андрей Тернити 提问时间:9/13/2023 最后编辑:Андрей Тернити 更新时间:9/20/2023 访问量:127
为什么 C 应用程序因为共享库而失败?
Why C app fail because of shared library?
问:
FFMpeg_MJPEG-transcode-VP9_C_Universe$ myExample/build-host/myExample
myExample/build-host/myExample: error while loading shared libraries: libswresample.so.4: cannot open shared object file: No such file or directory
我很惊讶,因为
chrpath -l myExample/build-host/myExample
myExample/build-host/myExample: RUNPATH=/home/q/FFMpeg_MJPEG-transcode-VP9_C_Universe/FFMpeg_themself/FFmpeg_build/lib
让我们检查一下里面有什么 lib/
FFMpeg_MJPEG-transcode-VP9_C_Universe/FFMpeg_themself/FFmpeg_build/lib$ ls
libavcodec.a libavdevice.a libavfilter.a libavformat.a libavutil.a libswresample.a libswscale.a pkgconfig
libavcodec.so libavdevice.so libavfilter.so libavformat.so libavutil.so libswresample.so libswscale.so
libavcodec.so.60 libavdevice.so.60 libavfilter.so.9 libavformat.so.60 libavutil.so.58 libswresample.so.4 libswscale.so.7
libavcodec.so.60.26.100 libavdevice.so.60.2.101 libavfilter.so.9.11.100 libavformat.so.60.12.100 libavutil.so.58.24.100 libswresample.so.4.11.100 libswscale.so.7.3.100
所以我的应用程序带有包含 libswresample.so.4 的文件夹的 RUNPATH 为什么会出错?看起来我的应用程序使用的另一个库 (.so) 没有相同的 RUNPATH。所以我用LD_LIBRARY_PATH方式修复它但我有新的错误
FFMpeg_MJPEG-transcode-VP9_C_Universe$ LD_LIBRARY_PATH=/home/q/FFMpeg_MJPEG-transcode-VP9_C_Universe/FFMpeg_themself/FFmpeg_build/lib myExample/build-host/myExample
Cannot open input file
Segmentation fault (core dumped)
此错误来自 libavformat 的 avformat_open_input()。为什么?
可能LD_LIBRARY_PATH方法不是好方法?让我们试试ldconfig的方式:
FFMpeg_MJPEG-transcode-VP9_C_Universe$ sudo bash -c 'cat <<EOF > /etc/ld.so.conf.d/myFFMpeg.conf
#My path to my FFMpeg build
#see details https://github.com/AndreiCherniaev/FFMpeg_MJPEG-transcode-VP9_C_Universe
${PWD}/FFMpeg_themself/FFmpeg_build/lib
EOF'
sudo ldconfig -v
测试时间示例:
FFMpeg_MJPEG-transcode-VP9_C_Universe$ myExample/build-host/myExample
Cannot open input file
Segmentation fault (core dumped)
同样的错误。为什么? 但是,如果我使用Qt Creator运行(没有构建,只是运行)我的示例,那么没有错误,我的代码工作正常。
可能是ldd日志有帮助吗?
FFMpeg_MJPEG-transcode-VP9_C_Universe$ ldd myExample/build-host/myExample
linux-vdso.so.1 (0x00007ffd7e38a000)
libavcodec.so.60 => /home/q/FFMpeg_MJPEG-transcode-VP9_C_Universe/FFMpeg_themself/FFmpeg_build/lib/libavcodec.so.60 (0x00007efd63e00000)
libavutil.so.58 => /home/q/FFMpeg_MJPEG-transcode-VP9_C_Universe/FFMpeg_themself/FFmpeg_build/lib/libavutil.so.58 (0x00007efd62c00000)
libavformat.so.60 => /home/q/FFMpeg_MJPEG-transcode-VP9_C_Universe/FFMpeg_themself/FFmpeg_build/lib/libavformat.so.60 (0x00007efd62800000)
libavfilter.so.9 => /home/q/FFMpeg_MJPEG-transcode-VP9_C_Universe/FFMpeg_themself/FFmpeg_build/lib/libavfilter.so.9 (0x00007efd62400000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007efd62000000)
libswresample.so.4 => not found
libvpx.so.7 => /lib/x86_64-linux-gnu/libvpx.so.7 (0x00007efd61c00000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007efd6507f000)
/lib64/ld-linux-x86-64.so.2 (0x00007efd6517a000)
libswscale.so.7 => not found
libswresample.so.4 => not found
在 cmake 阶段有“Found libswresample, version 4.11.100”, cmake log
FFMpeg_MJPEG-transcode-VP9_C_Universe$ cmake -G Ninja -DCMAKE_BUILD_TYPE:STRING=Debug -S myExample/src/ -B myExample/build-host/ --fresh
-- The C compiler identification is GNU 12.3.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
I found /home/q/FFMpeg_MJPEG-transcode-VP9_C_Universe/FFMpeg_themself/FFmpeg_build/
-- Found PkgConfig: /usr/bin/pkg-config (found version "1.8.1")
-- Checking for modules 'libavcodec;libavutil;libavformat;libswresample;libswscale;libavfilter'
-- Found libavcodec, version 60.26.100
-- Found libavutil, version 58.24.100
-- Found libavformat, version 60.12.100
-- Found libswresample, version 4.11.100
-- Found libswscale, version 7.3.100
-- Found libavfilter, version 9.11.100
-- Configuring done
-- Generating done
-- Build files have been written to: /home/q/FFMpeg_MJPEG-transcode-VP9_C_Universe/myExample/build-host
也许ffmpeg日志有帮助吗?
FFMpeg_MJPEG-transcode-VP9_C_Universe$ LD_LIBRARY_PATH=/home/q/FFMpeg_MJPEG-transcode-VP9_C_Universe/FFMpeg_themself/FFmpeg_build/lib FFMpeg_themself/bin/ffmpeg
ffmpeg version N-112061-g654e4b00e2 Copyright (c) 2000-2023 the FFmpeg developers
built with gcc 12 (Ubuntu 12.3.0-1ubuntu1~23.04)
configuration: --prefix=/home/q/FFMpeg_MJPEG-transcode-VP9_C_Universe/FFMpeg_themself/FFmpeg_build --pkg-config-flags=--static --extra-cflags=-I/home/q/FFMpeg_MJPEG-transcode-VP9_C_Universe/FFMpeg_themself/FFmpeg_build/include --extra-ldflags=-L/home/q/FFMpeg_MJPEG-transcode-VP9_C_Universe/FFMpeg_themself/FFmpeg_build/lib --extra-libs='-lpthread -lm' --ld=g++ --bindir=../bin --disable-x86asm --enable-libvpx --enable-shared
libavutil 58. 24.100 / 58. 24.100
libavcodec 60. 26.100 / 60. 26.100
libavformat 60. 12.100 / 60. 12.100
libavdevice 60. 2.101 / 60. 2.101
libavfilter 9. 11.100 / 9. 11.100
libswscale 7. 3.100 / 7. 3.100
libswresample 4. 11.100 / 4. 11.100
Hyper fast Audio and Video encoder
usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...
答:
1赞
Андрей Тернити
9/14/2023
#1
看起来问题是由于视频InFile的路径不正确。现在我修复了它,现在我可以运行我的代码了。我已经将我的存储库更新为最后一个代码。
评论
ldd myExample