linux 为什么C应用程序会因为共享库而失败?

uklbhaso  于 2023-10-16  发布在  Linux
关注(0)|答案(1)|浏览(126)

这是我的example基于官方code。我运行example并得到错误

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

所以我有一个应用程序与RUNPATH文件夹,包含libswresample.so.4为什么错误?看起来我的应用程序使用的另一个库(.so)没有相同的RUNPATH..所以我使用LD_LIBRARY_PATH way修复它,但我有新的错误

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 way不是好办法?让我们试试ldconfig way

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日志

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}...
rjee0c15

rjee0c151#

看起来问题是因为视频InFile的路径不正确。现在我修复它,现在我可以运行我的代码。我已经更新了我的repo到最后一个代码。

相关问题