Snapcraft custom method LD_LIBRARY_PATH

When creating a batch package, the wrapper script automatically appends $SNAP/usr/lib

to 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 dependencies are defined in stage-packages

my snapcraft.yaml, the above paths are not included in the shell script.

How do I get snapcraft to automatically add the path to all libraries to the wrapper script?

+3


source to share


1 answer


Snapcraft maintains a list of libraries common ways (e.g. /usr/lib/

, /usr/lib/<arch>

etc). If these directories exist, they will add them to the LD_LIBRARY_PATH

. Consider how Ubuntu "finds" libraries in unpredictable paths like the one you mentioned: this is one of the reasons /etc/ld.so.conf

. However, the typical way Ubuntu sends notifications of new libraries is with a hook that is run after the Debian package is installed. In the case of Snapcraft, these hooks never run - the stage packages are simply unpacked. This means that there is no easy way for Snapcraft to know that the scene package it just unpacked has the library in an unpredictable location.

While Snapcraft cannot help you automatically, you can do it yourself using one of two methods:



  • Create a wrapper script that installs LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$SNAP/usr/lib/lapack

    and then runs the executable you actually want to run. Then use this shell script in the section apps

    .
  • Use a new and as yet undocumented environment

    keyword like:

    apps:
      my-app:
        command: my-binary
        environment:
          LD_LIBRARY_PATH: $LD_LIBRARY_PATH:$SNAP/usr/lib/lapack
    
          

+6


source







All Articles