None of my stage-packages are being added to env path

I’m on ubuntu 16.04
When I add something as a stage package, it’s executable shows up in $SNAP/usr/bin/ and the relevant .so files in $SNAP/usr/lib/, but whenever I try to utilize these packages in my app, they fail. For instance, I will snap run --shell myapp and try lspci (which my app uses) and it says command not found, but then I navigate to $SNAP/usr/bin/ and do ./lspci and it then gives me the next problem,

libpci.so.3: cannot open shared object file: No such file or directory

So I do
export LD_LIBRARY_PATH=$SNAP/lib/x86_64-linux-gnu/
and then running the command works.
This is of course not ideal. What am I doing wrong such that this doesn’t happen automatically? What should I be putting in my snapcraft to fix this?

This is working as designed. You are running --shell which puts you inside the snap, but doesn’t setup the environment. These are (currently) configured via wrapper scripts which you’ll find in the root of the snap (ls $SNAP/command*.wrapper inside the snap). They setup the environment for the commands you expose via apps:. I imagine you don’t need lspci exposed to the outside world, but only used when called from myapp which likely works fine? By running --shell and omitting the wrapper shell, you’re not configuring the environment for myapp but running a random binary inside the snap. That’s why it fails to find the libs (no LD_LIBRARY_PATH).

So lets take a step back. What happens when myapp calls lspci when run inside the snap?

Okay, that makes more sense now. I mainly used lspci as an example. This was a long lasting issue in understanding that I had not sorted out. Thank you.

The issue I am currently facing, which I thought was an issue with the environment, is gnome-terminal. When trying to do gnome-terminal is also a stage package, which fails to launch from my snap. When running it from the shell (now using the export statements in the wrapper) I get the following error:

Traceback (most recent call last):
File “/snap/qtencodegui/x1/usr/bin/gnome-terminal”, line 9, in
from gi.repository import GLib, Gio
File “/snap/qtencodegui/x1/usr/lib/python3/dist-packages/gi/importer.py”, line 127, in find_module
‘introspection typelib not found’ % namespace)
ImportError: cannot import name GLib, introspection typelib not found

Any chance you can paste the entire yaml so we can debug it?

A depending software resource isn’t found, you have to locate it, stage it, and possibly modify the environment so that the snapped application can locate it.