`ld` with CMake not finding libraries from a `stage-snap`

Hey all,

I’m having a problem using stage-snaps with a CMake part:

(you’ll need to use mir-core20/latest/edge to reproduce locally)

The build goes well right up until it comes to linking, at which point it fails with:

[ 11%] Linking CXX executable egmde
/usr/bin/cmake -E cmake_link_script CMakeFiles/egmde.dir/link.txt --verbose=1
/usr/bin/c++  -isystem/root/stage/usr/include -pthread -g -Werror -Wall -pedantic -Wextra -fPIC -Wnon-virtual-dtor -std=c++17  -L/root/parts/egmde/install/lib -L/root/parts/egmde/install/usr/lib -L/root/parts/egmde/install/lib/x86_64-linux-gnu -L/root/parts/egmd
e/install/usr/lib/x86_64-linux-gnu -L/root/stage/lib -L/root/stage/usr/lib -L/root/stage/lib/x86_64-linux-gnu -L/root/stage/usr/lib/x86_64-linux-gnu -Wl,-z,defs CMakeFiles/egmde.dir/egmde.cpp.o CMakeFiles/egmde.dir/eglauncher.cpp.o CMakeFiles/egmde.dir/egwallpap
er.cpp.o CMakeFiles/egmde.dir/egwindowmanager.cpp.o CMakeFiles/egmde.dir/egworker.cpp.o CMakeFiles/egmde.dir/printer.cpp.o CMakeFiles/egmde.dir/egfullscreenclient.cpp.o CMakeFiles/egmde.dir/egshellcommands.cpp.o  -o egmde  -L/root/stage/usr/lib/x86_64-linux-gnu
-lmiral -lmircommon -lmircore -L/root/stage/usr/lib/x86_64-linux-gnu -lmircommon -lmircore -lwayland-client /usr/lib/x86_64-linux-gnu/libboost_filesystem.so.1.71.0 -lfreetype -lxkbcommon
/usr/bin/ld: warning: libmirserver.so.54, needed by /root/stage/usr/lib/x86_64-linux-gnu/libmiral.so, not found (try using -rpath or -rpath-link)
/usr/bin/ld: warning: libmirclient.so.10, needed by /root/stage/usr/lib/x86_64-linux-gnu/libmiral.so, not found (try using -rpath or -rpath-link)
/usr/bin/ld: warning: libmirplatform.so.21, needed by /root/stage/usr/lib/x86_64-linux-gnu/libmiral.so, not found (try using -rpath or -rpath-link)
/usr/bin/ld: warning: libyaml-cpp.so.0.6, needed by /root/stage/usr/lib/x86_64-linux-gnu/libmiral.so, not found (try using -rpath or -rpath-link)
/usr/bin/ld: warning: libcapnp-0.7.0.so, needed by /root/stage/usr/lib/x86_64-linux-gnu/libmircommon.so, not found (try using -rpath or -rpath-link)
/usr/bin/ld: warning: libkj-0.7.0.so, needed by /root/stage/usr/lib/x86_64-linux-gnu/libmircommon.so, not found (try using -rpath or -rpath-link)

Setting LD_LIBRARY_PATH for cmake --build makes it work, but that doesn’t go through snapcraftcl build. I’ve tried setting a number of CMAKE_ variables, none of which helped.

Should I be configuring something more? I’d have expected CMake to have all the necessary config for ${SNAPCRAFT_STAGE} to be done by the plugin… Or am I doing something else wrong altogether?

Maybe try using build-environment for this? This should work for core20

Thanks @sergiusens, that did work!

Can you comment on:

  1. why is build-environment a list[dict] rather than a plain dict?
  2. should the plugin not set LD_LIBRARY_PATH on its own?

Should I file bugs about either of those?

Also, https://snapcraft.io/docs/snapcraft-yaml-reference says:

Type: list[string]
A list of environment variable assignments that is applied during the build step…

This should probably say Type: list[dict] instead, and be more detailed on what that means.

1 Like

i have always been wondering why environment: and build-environment: differ in that regard too, it would be lovely if we had some consitency here instead …

1 Like

I’ve raised the issue of inconsistency between environment and build-environment in the past, but I think it was informally (maybe IRC) rather than on the forum.

1 Like

It is a list for composability. One of the reasons (there are others) we have command-chain for apps is that environment for apps cannot be composed. You can see this in action if you “snapcraft expand-extensions” when using the gnome-3-38 extension.

I believe @kyrofa has tried to propose for lists in app environment for snap.yaml already.

Here’s the snapd issue where allowing for lists is proposed as a solution to an ordering issue https://bugs.launchpad.net/snapd/+bug/1868460

well, i’d just be after consistency here, if you cant change environment, why not adapt build-environment instead so that they are the same syntax in the end …

We cannot change build-environment, but if you read the bug, you will see that you must change environment to support the semantics snapd expects (it is worked around today in snapcraft).

1 Like