Introduction

C and C++ are powerful programing languages that allow producing almost any kind of app. Building an AppImage from a C/C++ app is all about resolving all the dependencies. You can use the dependencies or package management system your prefer and even mix them. The only requirement is that all the shared libraries must be reachable to the linker when the AppImage build tool is executed.

In this case linuxdeploy will be used to create the AppImage file. This tool takes as input and AppDir. There we will install all the application dependencies using conan.

You can find the whole template here

Building the AppDir

To create the AppDir we will use the install method of your preferred build system. But instead of using /usr as target dir, we will install our binaries to AppDir like in the following examples:

cmake

cmake -DCMAKE_INSTALL_PREFIX=/usr .
DESTDIR=AppDir make install

Autotools

./configure --prefix=/usr
DESTDIR=AppDir make install

Qmake

qmake PREFIX=/usr .
INSTALL_ROOT=AppDir make install

Once your binaries are installed, the AppDir folder should look like this:

AppDir/usr/bin/my-app
AppDir/usr/share/applications/org.my-org.my-app.desktop
AppDir/usr/share/icons/hicolor/scalable/apps/org.my-org.my-app.svg

Notice that installing a desktop file and an icon is mandatory.

At this point if your applications doesn’t use any kind of plugins systems where shared libraries are loaded at run-time you can proceed to running linuxdeploy. If on the contrary your app require special plugins please read the “Including plugins” section.

Including plugins

If your app uses any kind of plugin system you must be sure that it’s capable to locate them using paths relative to the main binary location. And also manually include them in the right location inside the AppDir. Once done you can proceed to run linuxdeploy.

Generating the AppImage

Once you have an AppDir created you can proceed call linuxdeploy this way:

linuxdeploy --appdir=AppDir --output appimage

and you will get a nice AppImage file.

Build pipeline


## AppImage
build:AppImage:
  # old enough base system with conan pre-installed 
  image: conanio/gcc48:1.14.3
  stage: build
  before_script:
    # Upgrade Conan version
    - sudo pip install --upgrade conan
    # Automatic detection of your arch, compiler, etc.
    - conan user
    # Add AppImage specific repositories
    - conan remote add appimage-conan-community https://api.bintray.com/conan/appimage-conan-community/public-conan --insert=0
    # Prepare build environment
    - conan install .

  script:
    # enter conan virtual environment
    - . activate.sh
    - cmake -DCMAKE_INSTALL_PREFIX=/usr
    # Create AppDir
    - DESTDIR=AppDir make install
    # Create AppImage
    - linuxdeploy --appdir=AppDir --output appimage --desktop-file=AppDir/usr/share/applications/net.azubieta.cpp_appimage_template.desktop
    # exit conan virtual environment
    - . deactivate.sh

  artifacts:
    paths:
      - cpp_appimage_template*.AppImage*

Results

Once the build is done you can find the resulting file in the jobs artifacts view.

You may also want to get a reference to the latest produced artifact in order to show it in your applications site downloads page or in the pling product page. Use the following snippet to get your own download link address:

"https://www.opencode.net/<user name>/<project name>/-/jobs/artifacts/master/raw/<artifact file path>?job=<job name>"

Be sure to replace the user name, project name, artifact file path, and job name.