How do i add a executable to a snap

I tried searching a lot but most of the docs seemed complicated. I just want to know how would I add a simple C executable to a snap. I use the executable in my app for spawning a shell and running commands with it. Just needs access to /home/

Hi,

It depends, but this should get you going somewhere:

I guess you’ve already read Creating snapcraft.yaml - but suggest that you start with the easy first; try build a simple snap from this tutorial.

@joachimmg Thanks for the quick reply, still a bit confused between which one is corrrect. Suppose I want to install my cli on the users system before I install the actual GUI snap, do I add it in parts? Also if they are already available on apt or dnf would putting it in stage-packages be enough? And one last question, for some reason I cannot access the cli after I installed it with apt manually. I do have the home plug, is there some other plug I’m missing?

Edit1: Just tried putting my cli in stage-packages for some reason it says package not found? I can install it manually with apt install though

Hi,

It would be easier for anyone to help if you’d share your snapcraft.yaml. :slight_smile:

(But yes, if your package is in the ubuntu repository, I could be staged like this. Or you can add a package repository.)

Hey, my snap looks like this atm. But when I run snapcraft it says package not found. sudo apt install ccextractor works though

Hi,

I guess it’s because you’re using base: core18 (which is 18.04) and not core20 (20.04). and that ccextractor is not in bionic’s repository. However… the flutter-plugin is only available for core18.

So… You either need to provide a repository for ccextractor, build it from source or something :slight_smile:

I see it for 20.04 here So if I can add it to 18.04 there it should work? Will have to google how to do that. Also would updating the flutter .plugin be easier? I will need to find that source code too.

Also any idea why I can’t use the cli from the snap even though I have home plug?
Edit 1: I also tried changing the confinement mode to devmode which is supposed to give “full” access, but my GUI still says command not found.

Edit 2: For some reason ls works running from the GUI, but my cli ccextractor does not. Any idea?

you can not “just add” it to 18.04, it has been built against dependencies from 20.04 that are not available in 18.04 … you will either have to find a PPA or build it from source from your snapcraft.yaml in a dedicated part.

Ah ok, also any idea about these?

I also tried changing the confinement mode to devmode which is supposed to give “full” access, but my GUI still says command not found.

For some reason ls works running from the GUI, but my cli ccextractor does not. Any idea?

i’m not sure what you mean here, ccextractor does not exist in yoour snap and looking at your snapcraft.yaml the build of the snap should fail looking for that package, how do you expect it to execute ccextractor if it is not available ?

Ah no, I mean I ask the user to install ccextractor manually either from apt or build from source. I tried both of these but it still says command not found. Other commands like ls work from the snap.

that wont work, you would need classic confinement for using ccextractor from the host but “just calling an external binary” is not a criteria to get classic confinement granted:

you will need to ship it inside your snap one way or the other …

Well I should’ve mentioned it but I tried it in “devmode” too. Still says command not found. AFAIK devmode also is supposed to give access to all system resources?

yes, but not via the paths you are used to, devmode just turns the enforced confinement into reporting mode (so accessing external resources will not be blocked) but the app still runs inside the normal confined environment …

you might find the binary in /var/lib/snapd/hostfs/usr/bin or some such, but all the linker and library paths will not be correct so envoking it will fail like:

$ snap run --shell godd
...
$ /var/lib/snapd/hostfs/usr/bin/lshw
/var/lib/snapd/hostfs/usr/bin/lshw: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.27' not found (required by /var/lib/snapd/hostfs/usr/bin/lshw)
$

(godd is a --devmode snap on my system)

to get this working properly you will not get around shipping ccextractor …