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

问题描述 投票:0回答:1

这是我的示例,它基于官方代码。我运行 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 的应用程序到包含 libsresample.so.4 的文件夹,为什么会出现错误?看起来我的应用程序使用的另一个库(.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日志

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}...
linux shared-libraries libav ldd libswresample
1个回答
0
投票

看起来问题是因为视频 InFile 的路径不正确。现在我修复了它,现在我可以运行我的代码了。我将我的存储库更新为最后的代码。

© www.soinside.com 2019 - 2024. All rights reserved.