Library linter

The library linter is a Snapcraft linter that verifies whether any ELF file dependencies, typically libraries, are missing from a snap. It also verifies if any libraries are included in a snap but unused.

See Disable a linter for details on how to stop this linter from running.

How the linter helps

If a snapped application depends on libraries neither provided by the base system, nor included as a dependency, the snap may execute in an incorrect or unpredictable way. The library linter issues a warning if a missing dependency is detected.

Snap package size can be reduced by removing extra libraries that are not used by the applications in the snap. The library linter issues a warning if unused libraries are detected.

Linter warnings

The library linter issues a warning if:

  • An ELF file is missing any dependencies.
  • An ELF file has unused dependencies.

Example warnings

This terminal output shows two missing libraries (libcaca and libslang) and one unused library (libpng16).

Running linter: library
Lint warnings:
- library: my-app: missing dependency 'libcaca.so.0'.
- library: my-app: missing dependency 'libslang.so.2'.
- library: libpng16.so.16: unused library 'usr/lib/x86_64-linux-gnu/libpng16.so.16.37.0'. 

Fix flagged issues

The following guidelines describe how to address issues flagged by the linter.

To resolve a missing dependency:

  • Add the missing package to the part’s stage-packages key.

To resolve an unused library:

Library type Resolution
Dynamic linking If the stage-packages key of the part contains the unused library and no other entries, remove the library from the key. If the library contains other assets the snap needs, then instead move it to the part’s stage key and prefix it with a minus sign (-). It’s then excluded from the stage step of the build.
Static linking Static linking libraries must only be present at build time. So, the part should list the library in its build-package key, not stage-package. Again, if the library contains other necessary assets for the snap, then move it into the part’s stage key and prefix it with a minus sign.
Dynamic loading Snapcraft may falsely flag dynamic loading libraries as unused. In this case, don’t change its declaration in the recipe. Moving or removing it has a high risk of causing your app to malfunction at runtime. Instead, list it in the lint.ignore.<linter> key to suppress the warning for this library.

See Build and staging dependencies for further details about the stage-packages key.


Last updated a day ago.