Missing libpng when running my snap?

I am building my first desktop snap and don’t understand what I am doing wrong. It looks like I am missing libpng but adding them as dependencies does not seem to help.

My Vala GTK+3 app builds and runs fine with cmake outside of the snap environment. The snap builds fine but when I want to run the locally installed newly generated snap I get:

g_module_open() failed for /snap/mysnap/x1/usr/lib/x86_64-linux-gnu/gdk-pixbuf-2.0/2.10.0/loaders/libpixbufloader-png.so: /snap/mysnap/x1/snap/core/current/lib/x86_64-linux-gnu/libz.so.1: version `ZLIB_1.2.9' not found (required by /snap/mysnap/x1/usr/lib/x86_64-linux-gnu/libpng16.so.16)
g_module_open() failed for /snap/mysnap/x1/usr/lib/x86_64-linux-gnu/gdk-pixbuf-2.0/2.10.0/loaders/libpixbufloader-svg.so: /snap/mysnap/x1/snap/core/current/lib/x86_64-linux-gnu/libz.so.1: version `ZLIB_1.2.9' not found (required by /snap/mysnap/x1/usr/lib/x86_64-linux-gnu/libpng16.so.16)
/snap/mysnap/x1/usr/lib/x86_64-linux-gnu/libgtk-3-0/gtk-query-immodules-3.0: /snap/mysnap/x1/snap/core/current/usr/lib/x86_64-linux-gnu/libstdc++.so.6: version `CXXABI_1.3.11' not found (required by /snap/mysnap/x1/usr/lib/x86_64-linux-gnu/libmirclient.so.9)
/snap/mysnap/x1/usr/lib/x86_64-linux-gnu/libgtk-3-0/gtk-query-immodules-3.0: /snap/mysnap/x1/snap/core/current/lib/x86_64-linux-gnu/libz.so.1: version `ZLIB_1.2.9' not found (required by /snap/mysnap/x1/usr/lib/x86_64-linux-gnu/libpng16.so.16)
/snap/mysnap/x1/usr/lib/x86_64-linux-gnu/libgtk-3-0/gtk-query-immodules-3.0: /snap/mysnap/x1/snap/core/current/usr/lib/x86_64-linux-gnu/libstdc++.so.6: version `GLIBCXX_3.4.22' not found (required by /snap/mysnap/x1/usr/lib/x86_64-linux-gnu/libmircommon.so.7)
/snap/mysnap/x1/bin/desktop-launch: line 383: /snap/mysnap/x1/bin/mysnap: No such file or directory

I am new to Linux and Linux development in general so probably missing totally obvious here…

Relevant part of my snapcraft.yml:

grade: devel # must be ‘stable’ to release into candidate/stable channels
confinement: devmode # use ‘strict’ once you have the right plugs and slots

    command: desktop-launch $SNAP/bin/mysnap
    plugs: [home, x11]
    source: .
    plugin: cmake
      - -DCMAKE_BUILD_TYPE=Release
      - build-essential
      - valac
      - libxml2-dev
      - libpng-dev        <--- doesn't seem to help
      - zlib1g-dev        <--- doesn't seem to help
      - libglib2.0-dev    <--- doesn't seem to help
    after: [desktop-gtk3]

I install my test snap with sudo snap install mysnap_0.1_amd64.snap --devmode

Debian (hence Ubuntu) splits libraries into 2 parts: the libraryname-dev package which contains the header files and support files needed to build against the package, which you have correctly placed in the build-packages section; and the libraryname package (without the -dev) part which has the library itself, which needs to be included in the stage-packages section to ensure the library is shipped in your snap. You’re missing the stage-packages part.

I learned something new today!

I assume the "without the -dev" part is a convention and not all packages are following that? I found libpng-dev for example on Ubuntu 17.10 but libpng does not exist, libpng16-16, however, does. I suppose it’s try and error to know what package goes with what?

I added the stage-packages part:

--- 8< snip 8< -----
      - build-essential
      - valac
      - libxml2-dev
      - libpng-dev
      - zlib1g-dev
      - libglib2.0-dev
      - libxml2
      - libpng16-16
      - zlib1g
      - libglib2.0-0
--- 8< snip 8< -----

But it still throws the same error when running the snap. I suppose I am including the wrong packages? How do I know what packages I need?

Thank you!

I use the painfully manual way of running ldd against all the binaries or, failing that, readelf -d binary name | grep NEEDED . It isn’t pretty, but it gets me there.

Think I found it, I was building on 17.10 which, I found out by reading through the forum, is not recommended. Building on 16.04 in a virtual machine does work!

Thanks all!

1 Like

I made a little script called lddtostage which may come in handy anyway. Point it at a binary and it goes through the ldd output and prints the packages that you need from the archive. I realise it’s not useful for your case of running snapcraft on 17.10, but it might be handy in other case.

Here’s what it looks like when it runs…

alan@KinkPad-K340:~/bin$ ./lddtostage /snap/discord/current/usr/bin/discord