Simple C++ app with 2 libs

Hi
I have simple C++ daemon (backup app) and it use 2 libraries. I want make snap for it. Now I have my project stored locally, but I got an error:


$ 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.
Failed to pull source: unable to determine source type of 'Src/Libs/Common'.
Check that the URL is correct or consider specifying `source-type` for this part. See `snapcraft help sources` for more information.
I suppose I wrongly set source or source-subdir variables. I assume those variables are related to ../ directory where snapcraft.yaml is stored (in my case it is Snap dir). My snapcraft.yaml file is as follow:
name: backup
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

apps:
    kopia:
        command: desktop-launch $SNAP/bin/Kopia
#        environment:
#            LD_LIBRARY_PATH: $LD_LIBRARY_PATH:$SNAP/usr/local/lib

parts:
    smtpclient:
        plugin: qmake
        source: Src/Libs/SmtpClient-for-Qt-1.1
        source-subdir: Src/Libs/SmtpClient-for-Qt-1.1

    common:
        plugin: qmake
        source: Src/Libs/Common
        source-subdir: Src/Libs/Common

    kopia:
        after: [desktop-qt5, common, smtpclient]
        plugin: qmake
        source: Src/Kopia/
        source-subdir: Src/Kopia/
        options: [LIBS+=-L../../../stage/usr/local/lib]
#        options: [QT_INSTALL_LIBS=../../../stage/usr/local/lib]
        build-packages:
        - build-essential
        - qttools5-dev
        stage-packages:
        - coreutils
        - p7zip
        - libqt5core5a
        - libqt5network5
        - libxcomposite1
        - libxcursor1
        - libxinerama1
        - libxrandr2
        - libatk1.0-0
        - libgtk2.0-0

My questions are:

  1. Is this allowed to create snap from simple local file system based C++ project?
  2. Do I have to create git repository in order to properly create snap?

Try setting source to β€œ.” and remove source-subdir.

If you mean like this:


name: backup
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

apps:
    kopia:
        command: desktop-launch $SNAP/bin/Kopia

parts:
    smtpclient:
        plugin: qmake
        source: ./Src/Libs/SmtpClient-for-Qt-1.1

    common:
        plugin: qmake
        source: ./Src/Libs/Common

    kopia:
        after: [desktop-qt5, common, smtpclient]
        plugin: qmake
        source: ./Src/Kopia/
        options: [LIBS+=-L../../../stage/usr/local/lib]

        build-packages:
        - build-essential
        - qttools5-dev
        stage-packages:
        - coreutils
        - p7zip
        - libqt5core5a
        - libqt5network5
        - libxcomposite1
        - libxcursor1
        - libxinerama1
        - libxrandr2
        - libatk1.0-0
        - libgtk2.0-0

Now error is like this:


$ 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.
Failed to pull source: unable to determine source type of './Src/Libs/SmtpClient-for-Qt-1.1'.
Check that the URL is correct or consider specifying `source-type` for this part. See `snapcraft help sources` for more information.

Try specify the source without ./, also you may try setting the source-type property to local

No. Without ./ it not works at all. But with source-type: local it makes some progress and stops with error:
NotADirectoryError: β€˜/root/project/Src/Libs/Common’ is not a directory
And in true there is no such dir in virtual machine…

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

1 Like

But what am I suppose to do with this?
In my project I have following dirs:
Doc
Snap
Src
Systemd

Where Src has subdirs:
Kopia
Libs

Where Libs has subdirs:
Common
SmtpClient-for-Qt-1.1

I find this sensible dirs hierarhy. Is this something wrong with that?

My project direcotry structure is like this:


$ tree -d ./Kopia3
./Kopia3
β”œβ”€β”€ Doc
β”œβ”€β”€ Snap
β”œβ”€β”€ Src
β”‚   β”œβ”€β”€ Kopia
β”‚   β”‚   └── Src
β”‚   └── Libs
β”‚       β”œβ”€β”€ Common
β”‚       β”‚   β”œβ”€β”€ Src
β”‚       β”‚   └── Translations
β”‚       └── SmtpClient-for-Qt-1.1
β”‚           β”œβ”€β”€ demos
β”‚           β”‚   β”œβ”€β”€ demo1
β”‚           β”‚   β”œβ”€β”€ demo2
β”‚           β”‚   β”œβ”€β”€ demo3
β”‚           β”‚   └── demo4
β”‚           └── src
└── Systemd

[I corect preformated code - now it is display correctly.]
It is something worng with this? Should be Src Snap sub dir child?
Any help will be appreciated.

1 Like

According to your tree output it seems that the Common directory isn’t in the Src/Libs directory, are you sure this property is properly set?

./Src/Libs/Common is real sub dir in my project. Root is Kopia3 dir. Your filing is based on proportional font and on squeezing spaces by this crapy forum - with fixed with font you will be able see this hierarchy correctly. Sorry for this side effect but I cant force this forum to use β€œpreformated” style as expected - in most cases it is ignored or used partially (it makes idiotic many posts).
I use pastebin.com to show this file hierarchy correctly:
https://pastebin.com/96wYqERw

1 Like

Use the fenced code block markup for pre-formatted contents.

 $ tree -d ./Kopia3
    ./Kopia3
    β”œβ”€β”€ Doc
    β”œβ”€β”€ Snap
    β”œβ”€β”€ Src
    β”‚   β”œβ”€β”€ Kopia
    β”‚   β”‚   └── Src
    β”‚   └── Libs
    β”‚       β”œβ”€β”€ Common
    β”‚       β”‚   β”œβ”€β”€ Src
    β”‚       β”‚   └── Translations
    β”‚       └── SmtpClient-for-Qt-1.1
    β”‚           β”œβ”€β”€ demos
    β”‚           β”‚   β”œβ”€β”€ demo1
    β”‚           β”‚   β”œβ”€β”€ demo2
    β”‚           β”‚   β”œβ”€β”€ demo3
    β”‚           β”‚   └── demo4
    β”‚           └── src
    └── Systemd
1 Like

Try

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

and upload the snapcraft.log file somewhere.

1 Like

My current snap is:


name: backup
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

apps:
    kopia:
        command: desktop-launch $SNAP/bin/Kopia

parts:
    smtpclient:
        plugin: qmake
        source: ./Src/Libs/SmtpClient-for-Qt-1.1
        source-type: local

    common:
        plugin: qmake
        source: ./Src/Libs/Common
        source-type: local

    kopia:
        after: [common, smtpclient]
        plugin: qmake
        source: ./Src/Kopia
        source-type: local
        options: [LIBS+=-L../../../stage/usr/local/lib]

        build-packages:
        - build-essential
        - qttools5-dev
        stage-packages:
        - coreutils
        - p7zip
        - libqt5core5a
        - libqt5network5
        - libxcomposite1
        - libxcursor1
        - libxinerama1
        - libxrandr2
        - libatk1.0-0
        - libgtk2.0-0

And log, produced by command that you suggested, is here: https://pastebin.com/c57RYr9a

1 Like

NotADirectoryError: β€˜/root/project/Src/Libs/Common’ is not a directory

Is Src/Libs/Common a symbolic link?

Been lurking here, following this. I’m just curious. Can you give this snap project a try and let me know if it works in your environment?

https://github.com/jsseidel/testsnap

Note that it works if you remove β€œsource-subdir” and use β€œsource: ./src” as you do.

1 Like

I follow the testsnap source and source-type and source-subdir style and update my snapcraft.yaml:


name: backup
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

apps:
    kopia:
        command: desktop-launch $SNAP/bin/Kopia

parts:
    smtpclient:
        plugin: qmake
        source: .
        source-type: local
        source-subdir: Src/Libs/SmtpClient-for-Qt-1.1

    common:
        plugin: qmake
        source: .
        source-type: local
        source-subdir: Src/Libs/Common

    kopia:
        after: [common, smtpclient]
        plugin: qmake
        source: .
        source-type: local
        source-subdir: Src/Kopia
        options: [LIBS+=-L../../../stage/usr/local/lib]

        build-packages:
        - build-essential
        - qttools5-dev
        stage-packages:
        - coreutils
        - p7zip
        - libqt5core5a
        - libqt5network5
        - libxcomposite1
        - libxcursor1
        - libxinerama1
        - libxrandr2
        - libatk1.0-0
        - libgtk2.0-0

Current log error is here:
https://pastebin.com/j4Hi0G0J
My project sources are here:
http://szyk.jcom.pl/Kopia3.7z
(How ever it is not strictly open source project, you have my officially permissions to use it in testing purposes)
I checked it if it is compilable and it works as expected. It works also as expected - it does create backup of my files twice a week.
Warning: I use Kubuntu 18.04 Lts as my desktop system. Maybe this problems are due to slighty outdated distro? I. e. I also can’t create flatpack packages due to outdated flatpack in my distro.
I updated my posts in the way embrace code sections in β€œpre” and β€œcode” html tags.

1 Like

Just one quick thing. My build was able to get much further than yours without doing anything – well, almost anything. I had to rename Snap -> snap. I am using the snap version of snapcraft as well as the snap version of multipass. A build on my 18.04 LTS machine eventually failed because it couldn’t find some libs. I will play with this more tomorrow.

2 Likes

I have use

base: core18

Which use virtual machine (need to be enabled in the bios) because It reports an error: β€œsnap linker differ from system linker” (or something like this).

I will be glad if you post here step by step instruction how you build snap package for my Kopia3 on Ubuntu 18.04 system (list of necessary modifications in the project and bash commands will be enough - exclude required install packages - I can manage this on my own).
Thank you for your effort!

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. I think the override-build parts are not normally necessary if your project follows certain Makefile protocols like 'make install ’ etc, but I’m not familiar with qmake. Anyway, this will get you much further, I think:

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

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

parts:
    smtpclient:
        plugin: qmake
        source: .
        source-type: local
        source-subdir: Src/Libs/SmtpClient-for-Qt-1.1
        build-packages:
        - build-essential
        - qttools5-dev
    common:
        plugin: qmake
        source: .
        source-type: local
        source-subdir: Src/Libs/Common
        build-packages:
        - build-essential
        - qttools5-dev

    desktop-qt5:
      source: https://github.com/ubuntu/snapcraft-desktop-helpers.git
      source-subdir: qt
      plugin: make
      make-parameters: ["FLAVOR=qt5"]
      build-packages:
        - qtbase5-dev
        - dpkg-dev
      stage-packages:
        - 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

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

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.

There is no window - this is a daemon. But in order to run properly you have to edit ./Systemd/Kopia.ini and run InstallKopia.sh (for now I am not sure how to attach these files to snap and how to call InstallKopia.sh after installation).