Search code examples
linuxshared-librarieslibavlddlibswresample

Why C app fail because of shared library?


This is my example which is based on official code. I run example and get error

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

I surprised because

chrpath -l myExample/build-host/myExample
myExample/build-host/myExample: RUNPATH=/home/q/FFMpeg_MJPEG-transcode-VP9_C_Universe/FFMpeg_themself/FFmpeg_build/lib

Let's check what inside 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

So I have app with RUNPATH to folder that contains libswresample.so.4 Why error? Looks like another libraries (.so) that my app use haven't the same RUNPATH.. So I fix it using LD_LIBRARY_PATH way But I have new error

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)

This error is from avformat_open_input() from libavformat. Why?

May be LD_LIBRARY_PATH way not good way? Let's try 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

Time to test example:

FFMpeg_MJPEG-transcode-VP9_C_Universe$ myExample/build-host/myExample
Cannot open input file
Segmentation fault (core dumped)

The same error. Why? But if I run (no build just run) my example using Qt Creator then no error and my code works ok.

May be ldd log is helpful?

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

In cmake stage there is"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

May be ffmpeg log is helpful?

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

Solution

  • Looks like the problem was because of incorrect path to video InFile. Now I fix it and now I can run my code. I have already updated my repo to last code.