When building a snap package, the wrapper script automatically adds $SNAP/usr/lib
to the LD_LIBRARY_PATH
.
When building my package on docker, some libraries (in this case liblapack
and libblas
) are installed in subdirectories: $SNAP/usr/lib/lapack
and $SNAP/usr/lib/libblas
respectively.
Although all the dependencies are defined under stage-packages
in my snapcraft.yaml, the paths above are not included in the wrapper script.
How can I force snapcraft to add the path to all the libraries to the wrapper script automatically?
Snapcraft maintains a list of common library paths (e.g. /usr/lib/
, /usr/lib/<arch>
, etc.). If those directories exist, it will add them to LD_LIBRARY_PATH
. Think of how Ubuntu "finds" libs in such unpredictable paths as the one you mentioned: this is one of the reasons behind /etc/ld.so.conf
. However, the typical way packages notify Ubuntu of new libraries is in a hook that is run after the Debian package is installed. In the case of Snapcraft, those hooks are never run-- stage-packages are simply unpacked. This means Snapcraft has no easy way of learning that the stage-package it just unpacked has a library in an unpredictable place.
While Snapcraft cannot currently help you automatically, you can definitely do this yourself, using one of two ways:
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$SNAP/usr/lib/lapack
and then execs the binary you actually want to run. Then use that wrapper script in your apps
section.Make use of the new and as yet undocumented environment
keyword, like this:
apps:
my-app:
command: my-binary
environment:
LD_LIBRARY_PATH: $LD_LIBRARY_PATH:$SNAP/usr/lib/lapack
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With