Simple C++ app with 2 libs


Don’t know for sure, but my guess is that you’d maybe want to look for Kopia.ini somewhere in XDG_RUNTIME_DIR.

I’ve done stuff like the install script by creating another part like this, an example from another snap I have:

    plugin: dump
    source: .
    source-type: local
        plantuml: usr/bin/plantuml

Here, “plantuml” is a script I have in the root of my project directory. You can then add another “app” to snapcraft.yaml called “install-kopia” whose command is $SNAP/usr/bin/ Then, you can run it like:

snap run kopia.install-kopia

Something like that, anyway. Any apps you add after the first one can be run this way.


Thank you jsseidel!

This snap builds, installs, and runs (no window tho . . . not sure it’s supposed to have one) on my 18.04 machine with snap versions of snap and multipass.

What exactly command did you use? And where did you call them?
You recognize snap and multipass. As snap did you mean

base: core18
removed/commented from snapcraft.yaml file?
Is your Ubuntu 18.04 fully updated?
I ask you because I call script:

snapcraft clean
SNAPCRAFT_ENABLE_DEVELOPER_DEBUG=yes snapcraft 2>&1 | tee snapcraft.log

from Kopia3/snap and I have still error like this:
It seems to me like /usr/lib/qt5/bin/qmake cant see Src/Libs/Common/ file, but I don’t know how to check where sources of Common library are copied and I don’t know PWD where /usr/lib/qt5/bin/qmake is called. Especially when recommended way to build Qt projects is build outside source dir.


You don’t really need to care about this in Snapcraft as Snapcraft alway clean up the build step when it is required.


Check out the project-files keyword in the snapcraft help qmake command’s output.


I added line to common part:
project-files: []
And now it I have got really strange output:

$ snapcraft --debug                     
Using 'snapcraft.yaml': Project assets will be searched for from the 'snap' directory.
Launching a VM.
snap "core18" has no updates available                                          
Using 'snapcraft.yaml': Project assets will be searched for from the 'snap' directory.
Updating pull step for common (source changed)
Skipping pull desktop-qt5 (already ran)
Updating pull step for smtpclient (source changed)
'kopia' has dependencies that need to be staged: smtpclient common desktop-qt5
Skipping pull common (already ran)
Skipping pull desktop-qt5 (already ran)                                                                                                                                                                                                                                                                                     
Skipping pull smtpclient (already ran)                                                                                                                                                                                                                                                                                      
Building common                                                                                                                                                                                                                                                                                                             
qmake /root/parts/common/src/Src/Libs/Common/                                                                                                                                                                                                                                                                     
Cannot find file: /root/parts/common/src/Src/Libs/Common/                                                                                                                                                                                                                                                        
Failed to run 'qmake /root/parts/common/src/Src/Libs/Common/' for 'common': Exited with code 2.                                                                                                                                                                                                                   
Verify that the part is using the correct parameters and try again. 

I don’t have to mention I don’t have dir /root/parts/*
Och I just notice:

The /root/project folder is a SFTP mount point of the folder you run snapcraft in.

So how I can verify what was copied in to src/Src/Libs/Common/ dir in /root/parts/common/src/Src/Libs/Common/
It seems that was not copied!


NotADirectoryError: ‘/root/project/Src/Libs/Common’ is not a directory

Is Src/Libs/Common a symbolic link?

In my project it is real directory.


Please use the source keyword instead of source-subdir, use source: . indicates you want Snapcraft to copy the entire directory you’ve run snapcraft in as the common part’s source tree, which is likely not what you would’ve wanted.


Good point. More efficient. Here’s a working revised version:

name: kopia
version: '0.1'
summary: Simple backup daemon
description: |
    Simple backup daemon.

grade: devel # must be 'stable' to release into candidate/stable channels
confinement: devmode # use 'strict' once you have the right plugs and slots
base: core18

        command: desktop-launch $SNAP/bin/Kopia
          LD_LIBRARY_PATH: $LD_LIBRARY_PATH:$SNAP/usr/local/lib

        plugin: qmake
        source: ./Src/Libs/SmtpClient-for-Qt-1.1
        source-type: local
        - build-essential
        - qttools5-dev
        plugin: qmake
        source: ./Src/Libs/Common
        source-type: local
        - build-essential
        - qttools5-dev
      source-subdir: qt
      plugin: make
      make-parameters: ["FLAVOR=qt5"]
        - qtbase5-dev
        - dpkg-dev
        - libxkbcommon0
        - ttf-ubuntu-font-family
        - dmz-cursor-theme
        - light-themes
        - adwaita-icon-theme
        - gnome-themes-standard
        - shared-mime-info
        - libqt5gui5
        - libgdk-pixbuf2.0-0
        - libqt5svg5 # for loading icon themes which are svg
        - try: [appmenu-qt5] # not available on core18
        - locales-all

        after: [common, smtpclient, desktop-qt5]
        plugin: qmake
        source: ./Src/Kopia
        source-type: local
        options: [LIBS+=-L$SNAPCRAFT_STAGE/usr/local/lib]
        - build-essential
        - qttools5-dev
        override-build: |
          snapcraftctl build
          cp ./Kopia $SNAPCRAFT_PART_INSTALL/bin/.
        - coreutils
        - p7zip
        - libqt5core5a
        - libqt5network5
        - libxcomposite1
        - libxcursor1
        - libxinerama1
        - libxrandr2
        - libatk1.0-0
        - libgtk2.0-0

Note that the “./” is required to make it work. That is relative to the project directory, I assume. Not sure why a relative path doesn’t work.


Thank you for your effort!
But sadly it not work for me. I got error:
NotADirectoryError: '/root/project/Src/Libs/Common' is not a directory

Full log is here:
Is there any way to figure out what exactly contains /root/project/* dir?


@Szyk, I’m crafting a more detailed response as we speak that you might find helpful . . . Hang tight.


@Lin-Buo-Ren, please keep me honest here and correct anything I don’t have right.

If I were you, @Szyk, I would sudo apt purge --remove both multipass and snapcraft. Then:

snap install snapcraft --classic
snap install --beta multipass --classic

The snap versions support the core option and I’ve generally had better luck with it.

Use the latest snapcraft.yaml I posted today.


cd Kopia3
snapcraft clean
SNAPCRAFT_ENABLE_DEVELOPER_DEBUG=yes snapcraft 2>&1 | tee snapcraft.log

My log:

When I’m debugging, I immediately get a shell into the VM snapcraft creates (snapcraft-kopia) and then sudo su. Then cd /root, where you’ll see the snapcraft directories. In particular, the interesting directories for me are usually:

/root/parts/<part>/install: These are where the important bits of your parts builds end up. Stuff gets in here because snapcraft does the equivalent of make install DESTDIR=FOO/install, where FOO is the path to /root/parts/<part>/install. If your build doesn’t support that kind of make command, you can override the build like this:

    override-build: |
      snapcraftctl build # for housekeeping
      make foo bar baz
      cp ./Kopia $SNAPCRAFT_PART_INSTALL/usr/bin/.

Many, many snaps override build and use SNAPCRAFT_PART_INSTALL exclusively, although I’m sure this is discouraged officially. My general philosophy is that you shouldn’t ever have to change the way your project is built to accommodate snaps. Sometimes, projects have quirks or requirements that don’t fit into the general model snapcraft assumes for specific project types. For example, in one project of mine, I have to override the “gradle” build because I need to use a specific version of Java, which I set with JAVA_HOME in the override-build script. The default “gradle” plugin won’t work for me in that case.

So the first step is to really go part by part and make sure everything is working by part at first.

Then, you can start worrying about:

/root/stage: This is the staging area where all the parts install stuff is compiled together for the first time. If you have overlapping files, you’ll get errors because snapcraft doesn’t know how to resolve them. If stuff doesn’t show up where you expect in stage because of the way you’re building things, you can organize the files to change their location in stage:

      usr/bin/my-built-thing: usr/local/bin/thing

Note that those paths are relative to the stage directory.

Note that you should include everything that part will need to run at run-time under stage-packages and everything your part needs to build under build-packages. Don’t worry about the same packages being used in different parts. That’s okay. Think of the process as distinct part install file systems being overlayed in layers in stage, where things are then organized (organize) and copied to prime, where they are snapped.

Finally, everything ends up in prime, where it is snapped. I’m sure there are a billion details I’m not mentioning that might be important, but generally speaking that’s the flow that makes it work on my machine with my environment (i.e. snap versions of snapcraft and multipass in 18.04).

Hope that helps.


Thanks a lot!!! Now I have my first snap! There is some of work to make it usable (include additional files and run post install bash script) - but I will dig in to docs and eventually ask for details in separate thread.

Btw if you have some free time I will be glad to know:

When I’m debugging, I immediately get a shell into the VM snapcraft creates (snapcraft-kopia) and then sudo su. Then cd /root, where you’ll see the snapcraft directories.

Can you tell me how to “get a shell into the VM snapcraft creates”?


Awesome. Glad it works for you. Multipass is a really excellent VM manager in general. Here are a couple of useful things to do with it, including getting into the VM:

# Fire up a clean 18.04 VM
multipass launch 18.04 --name my-vm

# List VMs
multipass list

# Get a shell inside the VM (You'll be user 'multipass'.
# To get root: `sudo su` after logging in as user 'multipass'.)
multipass shell my-vm

# To stop a VM
multipass stop my-vm
# OR
# Inside the VM, `sudo shutdown now`

# To delete a VM
multipass delete my-vm
multipass purge

Snapcraft creates a multipass VM named “snapcraft-name” , where “name” is the name specified in snapcraft.yaml. When you snapcraft clean, snapcraft deletes and purges the VM.

Note that when snapcraft is done snapping something, it issues a 10 (?) minute shutdown of the VM, so you might have to cancel that. It’ll echo some info to the screen about how to cancel the shutdown so you can keep debugging.

Good luck with Kopia.


Aside from the multipass shell command, please checkout the --shell and --shell-after command option in the snapcraft help [pull|build|stage|prime] command’s output.