Bundling gcc into a snap


#1

My app, webots, includes an IDE from which users can invoke make and gcc to compile robot controllers.
I could manage to bundle build-essentials and libc6-dev in my stage-packages. However, when it comes compiling, the compilation process failed because it could not find stdio.h. I could easily fix that by adding a -I /snap/webots/current/usr/include -I /snap/webots/current/usr/include/x86_64-linux-gnu to the gcc command line. However it seems the gcc linker tries to link with /usr/lib/x86_64-linux-gnu/libmvec_nonshared.a and that fails in the snap sandbox. I could not find a way to replace this absolute path with /snap/webots/current/usr/lib/x86_64-linux-gnu/libmvec_nonshared.a as it seems to be hard coded in gcc at compile time. This thread suggest to recompile glibc in the snap: Building node extension modules at run-time, but it’s quite old and outdated (the instructions don’t work any more with gcc 7). Is that any simpler solution than recompiling gcc?


#2

You could use a layout to map /usr/lib/x86_64-linux-gnu/libmvec_nonshared.a to $SNAP/usr/lib/x86_64-linux-gnu/libmvec_nonshared.a, so that accessing the former really ends up using the latter. See https://snapcraft.io/docs/snap-layouts

There’s also snapcraft-preload, which may be of interest. See https://github.com/sergiusens/snapcraft-preload


#3

Using a layout as suggested worked out very well. Thank you!