LD_LIBRARY_PATH for custom libraries in snap

Hi all.
The program I run through a script, which lists the paths to the libraries as follows:

export PATH=$QTDIR_X86:$PATH
export LD_LIBRARY_PATH=$QTDIR_X86/../lib:.:./Simulation:$LD_LIBRARY_PATH

I’m doing in snapcraft.yaml like this:
BSP095launcherCoreSimulation:

    command: bin/run.sh $SNAP/bin/start_CORE_simulation.sh
    plugs: ['home', 'x11', 'opengl', 'gsettings', 'raw-usb', 'serial-port', 'network']
    environment:
        LD_LIBRARY_PATH: $SNAP/usr/lib/x86_64-linux-gnu:$SNAP/usr/lib/x86_64-linux-gnu/Simulation:$LD_LIBRARY_PATH

that to use my location in snap,not from the script path.

But running the program still try to find libraries on the way from the script.
What am I doing wrong?

Thanks.

Can you please try to print the environment variable from within the snap to see how it looks like?

You can easily do that by getting into a shell inside the snap environment with something along the lines of:

$ snap run --shell your-snap.app

If I understand you correctly then I did so snap run --shell bsp095project.BSP095launcherCoreSimulation
But what I can do inside the snap?

I think i doing it)

 ldd /snap/bsp095project/x1/bin/CORE 
        linux-vdso.so.1 =>  (0x00007fff49344000)
        libNetworkCommunication.so.0 => not found
        libLogging.so.0 => not found
        libUnitController.so.0 => not found
        libTherapyRunnersController.so.0 => not found
        libGenersControllerCommon.so.0 => not found
        libQt5Widgets.so.5 => /snap/bsp095project/x1/QT/5.5/gcc_64/lib/libQt5Widgets.so.5 (0x00007ff2fea66000)
        libQt5Network.so.5 => /snap/bsp095project/x1/QT/5.5/gcc_64/lib/libQt5Network.so.5 (0x00007ff2fe70c000)
        libQt5Core.so.5 => /snap/bsp095project/x1/QT/5.5/gcc_64/lib/libQt5Core.so.5 (0x00007ff2fdfc6000)
        libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007ff2fdc44000)
        libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007ff2fda2d000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007ff2fd664000)
        libQt5Gui.so.5 => /snap/bsp095project/x1/QT/5.5/gcc_64/lib/libQt5Gui.so.5 (0x00007ff2fce52000)
        libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007ff2fcc34000)
        libgobject-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0 (0x00007ff2fc9e1000)
        libgthread-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libgthread-2.0.so.0 (0x00007ff2fc7df000)
        librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007ff2fc5d6000)
        libglib-2.0.so.0 => /lib/x86_64-linux-gnu/libglib-2.0.so.0 (0x00007ff2fc2c5000)
        libXext.so.6 => not found
        libX11.so.6 => not found
        libGL.so.1 => not found
        libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007ff2fbfbb000)
        libicui18n.so.54 => not found
        libicuuc.so.54 => not found
        libicudata.so.54 => not found
        libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007ff2fbdb5000)
        /lib64/ld-linux-x86-64.so.2 (0x0000564fd6557000)
        libGL.so.1 => not found
        libffi.so.6 => /usr/lib/x86_64-linux-gnu/libffi.so.6 (0x00007ff2fbbac000)
        libpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007ff2fb93b000)

I seen that he correctly sees the way to QT libraries. But he does not see where to look custom libraries.

Get output
printenv

Now I have in the snapcraft.yaml,

BSP095launcherCoreSimulation:
        command: bin/run.sh $SNAP/bin/start_CORE_simulation.sh
        plugs: ['home', 'x11', 'opengl', 'gsettings', 'raw-usb', 'serial-port', 'network']
        environment:
            LD_LIBRARY_PATH: $SNAP/usr/BTL/
            LD_LIBRARY_PATH: $SNAP/usr/BTL/Simulation
            LD_LIBRARY_PATH: $SNAP/QT/5.5/gcc_64/lib
    BSP095launcherCore:
        command: bin/run.sh $SNAP/bin/start_CORE_hardware.sh
        plugs: ['home', 'x11', 'opengl', 'gsettings', 'raw-usb', 'serial-port', 'network']
        environment:
            LD_LIBRARY_PATH: $SNAP/usr/BTL/
            LD_LIBRARY_PATH: $SNAP/usr/BTL/CommProtV200
            LD_LIBRARY_PATH: $SNAP/QT/5.5/gcc_64/lib

but I’m not sure if I did the correct or not.

But output I have this

printenv 
XDG_VTNR=7
LC_PAPER=cs_CZ.UTF-8
KDE_MULTIHEAD=false
PAM_KWALLET5_LOGIN=/tmp/kwallet5_alexey.socket
XDG_SESSION_ID=2
LC_ADDRESS=cs_CZ.UTF-8
SSH_AGENT_PID=1927
LC_MONETARY=cs_CZ.UTF-8
GPG_AGENT_INFO=/home/alexey/.gnupg/S.gpg-agent:0:1
SNAP_USER_COMMON=/home/alexey/snap/bsp095project/common
SHELL=/bin/bash
TERM=xterm-256color
MAKEFLAGS=-j5
TMPDIR=/tmp
KONSOLE_DBUS_SERVICE=:1.26
GTK2_RC_FILES=/etc/gtk-2.0/gtkrc:/home/alexey/.gtkrc-2.0:/home/alexey/.config/gtkrc-2.0
QT_LINUX_ACCESSIBILITY_ALWAYS_ON=1
KONSOLE_PROFILE_NAME=Default
GS_LIB=/home/alexey/.fonts
GTK_RC_FILES=/etc/gtk/gtkrc:/home/alexey/.gtkrc:/home/alexey/.config/gtkrc
LC_NUMERIC=cs_CZ.UTF-8
WINDOWID=58720262
SHELL_SESSION_ID=bea1dea3dcb24c46914393fbff323b16
XDG_SESSION_CLASS=user                                                                                                                                                                                                                             
KDE_FULL_SESSION=true                                                                                                                                                                                                                              
SNAP_REEXEC=                                                                                                                                                                                                                                       
QTDIR_X86=/media/free/Qt/5.5/gcc_64/bin                                                                                                                                                                                                            
USER=alexey                                                                                                                                                                                                                                        
LD_LIBRARY_PATH=/snap/bsp095project/x1/QT/5.5/gcc_64/lib                                                                                                                                                                                           
LC_TELEPHONE=cs_CZ.UTF-8                                                                                                                                                                                                                           
QT_ACCESSIBILITY=1                                                                                                                                                                                                                                 
LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=00:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.m4a=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.oga=00;36:*.opus=00;36:*.spx=00;36:*.xspf=00;36:                                           
XDG_SESSION_PATH=/org/freedesktop/DisplayManager/Session1                                                                                                                                                                                          
XDG_SEAT_PATH=/org/freedesktop/DisplayManager/Seat0                                                                                                                                                                                                
QT_AUTO_SCREEN_SCALE_FACTOR=0                                                                                                                                                                                                                      
SSH_AUTH_SOCK=/tmp/ssh-zYUGNvCvP3gj/agent.1877                                                                                                                                                                                                     
SNAP_LIBRARY_PATH=/var/lib/snapd/lib/gl:/var/lib/snapd/void                                                                                                                                                                                        
SNAP_COMMON=/var/snap/bsp095project/common                                                                                                                                                                                                         
SESSION_MANAGER=local/alexey-ProBook-650:@/tmp/.ICE-unix/1995,unix/alexey-ProBook-650:/tmp/.ICE-unix/1995                                                                                                                                          
DEFAULTS_PATH=/usr/share/gconf//usr/share/xsessions/plasma.default.path                                                                                                                                                                            
SNAP_USER_DATA=/home/alexey/snap/bsp095project/x1                                                                                                                                                                                                  
SNAP_DATA=/var/snap/bsp095project/x1
XDG_CONFIG_DIRS=/etc/xdg/xdg-/usr/share/xsessions/plasma:/etc/xdg
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
DESKTOP_SESSION=/usr/share/xsessions/plasma
TEMPDIR=/tmp
LC_IDENTIFICATION=cs_CZ.UTF-8
XDG_SESSION_TYPE=x11
PWD=/home/alexey
KDE_SESSION_UID=1000
LANG=en_US.UTF-8
MANDATORY_PATH=/usr/share/gconf//usr/share/xsessions/plasma.mandatory.path
LC_MEASUREMENT=cs_CZ.UTF-8
KONSOLE_DBUS_SESSION=/Sessions/1
SNAP_REVISION=x1
XDG_SEAT=seat0
COLORFGBG=15;0
SHLVL=2
HOME=/home/alexey/snap/bsp095project/x1
KDE_SESSION_VERSION=5
SNAP_NAME=bsp095project
LANGUAGE=en_US:ru:cs
XCURSOR_THEME=breeze_cursors
LOGNAME=alexey
XDG_SESSION_DESKTOP=KDE
DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-BhhhvWsbA3,guid=9fb41db7d797fd33d57531f059534ace
XDG_DATA_DIRS=/usr/share//usr/share/xsessions/plasma:/usr/local/share/:/usr/share/:/var/lib/snapd/desktop
SNAP_ARCH=amd64
LESSOPEN=| /usr/bin/lesspipe %s
SNAP_VERSION=1.0
DISPLAY=:0
XDG_RUNTIME_DIR=/run/user/1000/snap.bsp095project
PROFILEHOME=
XDG_CURRENT_DESKTOP=KDE
SNAP=/snap/bsp095project/x1
LESSCLOSE=/usr/bin/lesspipe %s %s
LC_TIME=cs_CZ.UTF-8
COLORTERM=truecolor
XAUTHORITY=/run/user/1000/.Xauthority
LC_NAME=cs_CZ.UTF-8
_=/usr/bin/printenv

I recommend deleting lines
environment:
LD_LIBRARY_PATH: $SNAP/usr/BTL/
LD_LIBRARY_PATH: $SNAP/usr/BTL/Simulation
LD_LIBRARY_PATH: $SNAP/QT/5.5/gcc_64/lib

And add line in bin/run.sh
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$SNAP/usr/BTL/:$SNAP/usr/BTL/Simulation/:$SNAP/QT/5.5/gcc_64/lib/"

Well, about the transfer to the script of these lines I understood.
But how correctly to specify here that for one version the program needs to be
LD_LIBRARY_PATH: $SNAP/usr/BTL/Simulation
and for another use this path?
LD_LIBRARY_PATH: $SNAP/usr/BTL/CommProtV200

Thx for ansver.

ADD (not REPLACE) all the paths you need to LD_LIBRARY_PATH
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$SNAP/path/to1/:$SNAP/path/to2/:$SNAP/path/to3/"

OR

file bin/start_CORE_simulation.sh contain
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$SNAP/path/to1/:$SNAP/path/to2/"

file bin/start_CORE_hardware.sh contain
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$SNAP/path/to4/:$SNAP/path/to5/"

Could you explain why it’s better to move the settings from snapcraft.yaml file to run.sh?
Is this better or is there any reason?

Thanks for those details. The problem there is that snapcraft is creating a wrapper to make it simpler for getting certain applications working fine, and the content of that wrapper depends on which parts are being used to build the snap. As part of that, it’s setting $LD_LIBRARY_PATH so the binaries inside the snap can see their libraries in the expected path.

That’s why using run.sh will work: your run.sh will be called after snapcraft’s wrapper, so the path won’t be changed further.

Have changed that that you specified, transferred in a script.
But the logs show the path line from the system where I build the project.

LC_PAPER=cs_CZ.UTF-8
XDG_VTNR=7
SSH_AGENT_PID=1927
PAM_KWALLET5_LOGIN=/tmp/kwallet5_alexey.socket
LC_ADDRESS=cs_CZ.UTF-8
XDG_SESSION_ID=2
KDE_MULTIHEAD=false
LC_MONETARY=cs_CZ.UTF-8
GPG_AGENT_INFO=/home/alexey/.gnupg/S.gpg-agent:0:1
SNAP_USER_COMMON=/home/alexey/snap/bsp095project/common
SHELL=/bin/bash
TERM=xterm-256color
MAKEFLAGS=-j5
TMPDIR=/tmp
GTK2_RC_FILES=/etc/gtk-2.0/gtkrc:/home/alexey/.gtkrc-2.0:/home/alexey/.config/gtkrc-2.0
KONSOLE_DBUS_SERVICE=:1.26
QT_LINUX_ACCESSIBILITY_ALWAYS_ON=1
KONSOLE_PROFILE_NAME=Default
GTK_RC_FILES=/etc/gtk/gtkrc:/home/alexey/.gtkrc:/home/alexey/.config/gtkrc
GS_LIB=/home/alexey/.fonts
WINDOWID=58720262
LC_NUMERIC=cs_CZ.UTF-8
SHELL_SESSION_ID=37652a7a9029497091a1491ea783b9bf
SNAP_REEXEC=
XDG_SESSION_CLASS=user
QTDIR_X86=/media/free/Qt/5.5/gcc_64/bin      <--

For example,
BSP095launcherCoreSimulation:
command: bin/run.sh $SNAP/bin/start_CORE_simulation.sh

The order of calling scripts
command-BSP095launcherCoreSimulation.wrapper -> bin/run.sh -> $SNAP/bin/start_CORE_simulation.sh

Verify your bin/run.sh and $SNAP/bin/start_CORE_simulation.sh
The string must be
$LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$SNAP/that/you/want/"

This wrong! The path can not be absolute
QTDIR_X86=/media/free/Qt/5.5/gcc_64/bin

Maybe
QTDIR_X86=$SNAP/media/free/Qt/5.5/gcc_64/bin
???

All QT libraries and modules have $SNAP/QT.
/media/free/Qt/5.5/gcc_64/bin it’s where a have on my comp QT, but I do not know where it takes this path and puts it in snap.

in run.sh i have
#setting for app
file $SNAP/bin/start_CORE_simulation.sh contain
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$SNAP/usr/BTL/:$SNAP/usr/BTL/Simulation/:$SNAP/QT/5.5/gcc_64/lib/"
file $SNAP/bin/start_CORE_hardware.sh contain
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$SNAP/usr/BTL/:$SNAP/usr/BTL/CommProtV200/:$SNAP/QT/5.5/gcc_64/lib/"
file $SNAP/bin/start_GUI.sh contain
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$SNAP/usr/BTL/:$SNAP/QT/5.5/gcc_64/lib/"
file $SNAP/bin/start_maintenance_hardware.sh contain
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$SNAP/usr/BTL/:$SNAP/QT/5.5/gcc_64/lib/"

I’m making you snap the package. It will be easier for me.