Binary file does not find libraries in subdir if run as snap package

Hi.

I’m quite new to creating snap packages, and this is one of my first attempts. I would like to pack an old program (sancho, a front-end for p2p software), that basically is just a binary file (the executable) and a subfolder (‘lib’) with some library dependencies.

I am able to create the snap package (sancho-snap) and install it. However, when I run it (sancho-snap). It can’t find those libraries. But if I run the same file directly, it runs without an issue.

It’s as if, once the program is in the form of a snap package, it can’t “see” the subdirectories in their relative path.

This is the folder structure:

$ ls -R
.:
distrib  lib  sancho

./distrib:
AUTHORS      preview.sh      sancho-48.xpm            sancho_fr_FR.properties  sancho_nl_NL.properties        sancho.reg
ChangeLog    README          sancho-64.png            sancho_gl_ES.properties  sancho_no_NO.properties        sancho_ru_RU.properties
CPL.txt      sancho-128.png  sancho_ca_ES.properties  sancho_hu_HU.properties  sancho_pl_PL.properties        sancho_zh_CN.properties
LGPL.txt     sancho-16.xpm   sancho_de_DE.properties  sancho.icns              sancho_pl_PL.properties_ascii  sendalltorrents
LICENSE.txt  sancho-256.png  sancho_es_ES.properties  sancho.ico               sancho.properties
preview.bat  sancho-32.xpm   sancho_et_EE.properties  sancho_it_IT.properties  sancho_pt_BR.properties

./lib:
libswt-atk-gtk-3509.so    libswt-glx-gtk-3509.so    libswt-mozilla-gcc3-gtk-3509.so  libswt-xpcominit-gtk-3509.so
libswt-awt-gtk-3509.so    libswt-gnome-gtk-3509.so  libswt-mozilla-gtk-3509.so       libswt-xulrunner-gtk-3509.so
libswt-cairo-gtk-3509.so  libswt-gtk-3509.so        libswt-pi-gtk-3509.so

So basically, when I run the program inside the snap package:

user@host:/$ snap run --shell sancho-snap
user@host:/$ cd /snap/sancho-snap/current/
user@host:/snap/sancho-snap/current$ ./sancho 
Exception in thread "main" java.lang.UnsatisfiedLinkError: no swt-pi-gtk-3509 or swt-pi-gtk in swt.library.path, java.library.path or the jar file
        at org.eclipse.swt.internal.Library.loadLibrary(Unknown Source)
        at org.eclipse.swt.internal.Library.loadLibrary(Unknown Source)
        at org.eclipse.swt.internal.gtk.OS.<clinit>(Unknown Source)
        at org.eclipse.swt.internal.Converter.wcsToMbcs(Unknown Source)
        at org.eclipse.swt.internal.Converter.wcsToMbcs(Unknown Source)
        at org.eclipse.swt.widgets.Display.<clinit>(Unknown Source)
        at sancho.core.Sancho.main(Sancho.java:202)

But if I just go to /snap/sancho-snap/current and I run the program, works just fine:

user@host:/snap/sancho-snap$ cd /snap/sancho-snap/current/
user@host:/snap/sancho-snap/current$ ./sancho 
[program starts normally]

Any ideas what could be the issue? I’ve spent hours trying already.

how does the apps block in your snapcraft.yaml look like ? do you hand the correct options to the java interpreter to use the correct search paths (or set the right env variables alternatively) ?