Missing symlinks to shared libraries when staging `ffmpeg` package


I’m trying to add ffmpeg (and mpv) to a snap I’m building (see Snapcraft recipe).

The snap builds, but when I snap run --shell into it, I cannot execute ffmpeg:

$ ffmpeg
ffmpeg: error while loading shared libraries: libblas.so.3: cannot open shared object file: No such file or directory

This file is present in my snap, in /snap/checkbox-kivu-classic/current/usr/lib/x86_64-linux-gnu/blas/libblas.so.3.

To try to understand what was going on, I installed ffmpeg from the repos using sudo apt install ffmpeg. After installation, I can see the following:

$ ll /usr/lib/x86_64-linux-gnu/libblas.so.3
lrwxrwxrwx 1 root root 47 Nov 27  2022 /usr/lib/x86_64-linux-gnu/libblas.so.3 -> /etc/alternatives/libblas.so.3-x86_64-linux-gnu

But in my snap, there is no such symlink:

$ ll /snap/checkbox-kivu-classic/current/usr/lib/x86_64-linux-gnu/libblas.so.3
ls: cannot access '/snap/checkbox-kivu-classic/current/usr/lib/x86_64-linux-gnu/libblas.so.3': No such file or directory

If I manually append the path to LD_LIBRARY_PATH, ffmpeg finds it, but then chokes on the next library it requires:


$ LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/snap/checkbox-kivu-classic/current/usr/lib/x86_64-linux-gnu/blas ffmpeg
ffmpeg: error while loading shared libraries: liblapack.so.3: cannot open shared object file: No such file or directory

If I keep doing that for every library, I can eventually run the ffmpeg command:

$ LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/snap/checkbox-kivu-classic/current/usr/lib/x86_64-linux-gnu/blas:/snap/checkbox-kivu-classic/current/usr/lib/x86_64-linux-gnu/lapack ffmpeg
ffmpeg version 4.4.2-0ubuntu0.22.04.1 Copyright (c) 2000-2021 the FFmpeg developers
  built with gcc 11 (Ubuntu 11.2.0-19ubuntu1)
  configuration: --prefix=/usr --extra-version=0ubuntu0.22.04.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libdav1d --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librabbitmq --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzimg --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-pocketsphinx --enable-librsvg --enable-libmfx --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
  libavutil      56. 70.100 / 56. 70.100
  libavcodec     58.134.100 / 58.134.100
  libavformat    58. 76.100 / 58. 76.100
  libavdevice    58. 13.100 / 58. 13.100
  libavfilter     7.110.100 /  7.110.100
  libswscale      5.  9.100 /  5.  9.100
  libswresample   3.  9.100 /  3.  9.100
  libpostproc    55.  9.100 / 55.  9.100
Hyper fast Audio and Video encoder
usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...

Use -h to get full help or, even better, run 'man ffmpeg'

Two questions:

  • Is it normal that a package like ffmpeg added through stage-packages properly installs its dependencies, but fails to create the appropriate symlinks?
  • As a workaround, should I add the following to each of my apps’ sections?

Thanks in advance!

You can try my ffmpeg content snap if you’re on core22.

To use it, do,

    interface: content
    target: ffmpeg-platform
    default-provider: ffmpeg-2204

  example: //part name that needs ffmpeg to build
      - ffmpeg-2204-sdk
      - PKG_CONFIG_PATH: /snap/ffmpeg-2204-sdk/current/usr/lib/$CRAFT_ARCH_TRIPLET/pkgconfig:$PKG_CONFIG_PATH
      - PATH: /snap/ffmpeg-2204-sdk/current/usr/bin:$PATH
      - LD_LIBRARY_PATH: /snap/ffmpeg-2204-sdk/current/usr/lib/$CRAFT_ARCH_TRIPLET:$LD_LIBRARY_PATH

  example: //app name that needs ffmpeg to run
      PATH: $SNAP/ffmpeg-platform/usr/bin:$PATH

Thanks for your answer!

Unfortunately, that doesn’t really solve my problem because:

  • mvp suffers from the same problem
  • it would require me to add en environment: section to all my apps (which is probably what I’m gonna end up doing :))

Yoy can add environment: on a global level IIRC…