Can't create BMP image with ImageMagick inside Snap container

73 Views Asked by At

I have a working C code that uses for ImageMagick for creation of BMP files. For unknown to me reason this code doesn't work inside Snap container.

Minimal code snippet for testing if creating a BMP blob is possible.

#include <wand/magick_wand.h>

int main()
{

    system("convert -list format");
    MagickWand *mw = NULL;

    int width, height;

    MagickWandGenesis();

    mw = NewMagickWand();

    PixelWand *bg = NewPixelWand();
    PixelSetColor(bg, "white");
    MagickNewImage(mw, 20, 20, bg);
    PixelWand *fg = NewPixelWand();
    PixelSetColor(fg, "black");
    DrawingWand *dw = NewDrawingWand();
    DrawSetFillColor(dw, fg);

    MagickDrawImage(mw, dw);
    MagickResetIterator(mw);
    MagickSetImageFormat(mw, "bmp");
    size_t l;
    unsigned char *img = MagickGetImageBlob(mw, &l);

    ExceptionType severity;
    char *returnCode = MagickGetException(mw, &severity);
    printf("MagickGetException: %s %d\n", returnCode, severity);

    MagickRelinquishMemory(img);

    MagickWandTerminus();
}

If everything is OK it should printf 0 and no exception (that's what happens on host). Unfortunately inside Snap it printfs:

"MagickGetException: no decode delegate for this image format `' @ error/blob.c/ImageToBlob/1689 420".

On my host machine I have installed:

  1. imagemagick-6.q16
  2. libmagick++-6.q16-8
  3. libmagickcore-6-arch-config
  4. libmagickcore-6-headers
  5. libmagickcore-6.q16-6
  6. libmagickcore-6.q16-6-extra
  7. libmagickcore-6.q16-dev
  8. libmagickcore-dev
  9. libmagickwand-6-headers
  10. libmagickwand-6.q16-6
  11. libmagickwand-6.q16-dev
  12. libmagickwand-dev

My snapcraft.yaml

name: __APP_NAME_VERSION__
base: core20
version: '__APP_VERSION__'
summary: __APP_PRETTY_NAME_VERSION__
icon: __APP_ICON__
description: |
  __APP_DESCRIPTION__

architectures:
  - build-on: amd64
  - build-on: i386

grade: stable
confinement: classic
compression: lzo

package-repositories:
  - type: apt
    ppa: beineri/opt-qt-5.15.2-focal

apps:
  __APP_NAME_VERSION__:
    command: wand
    environment:
      DISABLE_WAYLAND: 1
      QT_QPA_PLATFORMTHEME: gtk3
      GDK_BACKEND: x11
      CLUTTER_BACKEND: x11
      QTWEBENGINE_DISABLE_SANDBOX: 1
      PATH: "${PATH}:/opt/qt515/bin"
      QTDIR: $SNAP/opt/qt515
      SNAP_DESKTOP_RUNTIME: $SNAP
      QT_PLUGIN_PATH: $SNAP/opt/qt515/plugins:$QT_PLUGIN_PATH
      QTWEBENGINEPROCESS_PATH: $SNAP/usr/lib/$SNAPCRAFT_ARCH_TRIPLET/qt5/libexec
      LD_LIBRARY_PATH: $SNAP/opt/qt515/lib:/var/lib/snapd/lib/gl:/var/lib/snapd/lib/gl32:/var/lib/snapd/void:$SNAP/lib:$SNAP/usr/lib:$SNAP/lib/$SNAPCRAFT_ARCH_TRIPLET:$SNAP/usr/lib/$SNAPCRAFT_ARCH_TRIPLET:$SNAP/usr/lib/x86_64-linux-gnu/dri

    plugs:
    - desktop
    - desktop-legacy
    - gsettings
    - home
    - opengl
    - audio-playback
    - removable-media
    - unity7
    - x11
    - mount-observe
    - network
    - network-control
    - network-observe
    - network-bind
    - wayland

parts:
  __APP_NAME_VERSION__:
    plugin: nil
    source: "src"
    build-environment:
    - PATH: "${PATH}:/opt/qt515/bin"
    - QTDIR: "/opt/qt515"
    build-packages:
    - build-essential
    - python3
    - python2
    - python3-pip
    - uglifyjs.terser
    - openjdk-11-jre-headless
    - rsync
    - git
    - imagemagick
    - libglib2.0-dev
    - libglibmm-2.4-dev
    - libcap-dev
    - libgtk2.0-dev
    - libjansson-dev
    - libarchive-dev
    - libmagickwand-6.q16-dev
    - libconfig-dev
    - libmicrohttpd-dev
    - libsqlite3-dev
    - libssl-dev
    - libpcap-dev
    - libstdc++-10-dev
    - libcurl3-gnutls-dev
    - libgl-dev
    - qt515base 
    - qt515webengine
    - qt515wayland
    - qt515tools
    override-build: |
      cc -o wand wand.c `pkg-config --cflags --libs MagickWand`
      cp wand ${SNAPCRAFT_PART_INSTALL}/
    stage-packages:
    - libmagickcore-6.q16-6
    - libmagickcore-6.q16hdri-6
    - libmagickcore-6.q16-6-extra
    - libmagickcore-6.q16hdri-6-extra
    - libmagick++-6.q16-8
    - libmagick++-6.q16hdri-8
    - libgraphicsmagick++-q16-12
    - libgraphicsmagick-q16-3
    - libmagickwand-6.q16-6
    - libmagickwand-6.q16hdri-6
    - dbus-x11
    - libcurl3-gnutls
    - libxml2
    - libssl1.1
    - libxcb1
    - libuuid1
    - liblzma5
    - libmicrohttpd12
    - libarchive13
    - libpcap0.8
    - libglibmm-2.4-1v5
    - libjansson4
    - libconfig9
    - libsqlite3-0
    - libexpat1
    - libwayland-egl1
    - libwayland-egl++0
    - libwayland-egl1-mesa
    - net-tools
    - libgl1-mesa-dri
    - adwaita-icon-theme
    - dmz-cursor-theme
    - fontconfig
    - gnome-themes-standard
    - freeglut3
    - libgdk-pixbuf2.0-0
    - libglib2.0-0
    - libglib2.0-bin
    - libglu1-mesa
    - libgtk2.0-0
    - libgtk-3-0
    - libice6
    - libxkbcommon0
    - light-themes
    - locales
    - locales-all
    - shared-mime-info
    - ttf-ubuntu-font-family
    - xdg-user-dirs
    - libfcitx-gclient1
    - libfcitx-utils0
    - fcitx-module-dbus
    - fcitx
    - ibus-gtk3
    - libibus-1.0-5
    - libcanberra0
    - libcanberra-gtk0
    - libcanberra-gtk-module
    - libcanberra-gtk3-0
    - libcanberra-gtk3-module
    - qt515base 
    - qt515webengine
    - qt515wayland


This is a rather complex snapcraft, but it is used for a much bigger app. It is modified to compile this single C file. As you can see, I've added all the ImageMagick packages as stage-packages. As far as I know, I don't need anything extra to work with simple BMPs, yet it is not working, claiming lack of required delegate.

I would be grateful for any advice on this issue.

Edit 1: Added identify -list configure per advice to the snap container. It is called during snap priming. Results are like this:

Path: /usr/lib/x86_64-linux-gnu/ImageMagick-6.9.10//config-Q16/configure.xml

Name           Value
-------------------------------------------------------------------------------
CC             gcc
CFLAGS         -I/usr/include/libxml2   -I/usr/include/libpng16  -I/usr/include/pango-1.0 -I/usr/include/fribidi -I/usr/include/harfbuzz -I/usr/include/cairo -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/pixman-1 -I/usr/include/uuid -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/OpenEXR  -I/usr/include/lqr-1 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include  -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/uuid -I/usr/include/freetype2 -I/usr/include/libpng16 -pthread    -fopenmp -g -O2 -fdebug-prefix-map=/build/imagemagick-gtb5on/imagemagick-6.9.10.23+dfsg=. -fstack-protector-strong -Wformat -Werror=format-security -Wall -fexceptions -pthread -DMAGICKCORE_HDRI_ENABLE=0 -DMAGICKCORE_QUANTUM_DEPTH=16
CODER_PATH     /usr/lib/x86_64-linux-gnu/ImageMagick-6.9.10/modules-Q16/coders
CONFIGURE      ../../configure  '--build=x86_64-linux-gnu' '--includedir=${prefix}/include' '--mandir=${prefix}/share/man' '--infodir=${prefix}/share/info' '--localstatedir=/var' '--libdir=${prefix}/lib/x86_64-linux-gnu' '--libexecdir=${prefix}/lib/x86_64-linux-gnu' '--runstatedir=/run' '--disable-maintainer-mode' '--disable-dependency-tracking' '--enable-reproducible-build' '--prefix=/usr' '--libdir=/usr/lib/x86_64-linux-gnu' '--docdir=/usr/share/doc/imagemagick-6-common/html' '--with-extra-doc-dir= (on debian system you may install the imagemagick-6 package)' '--sysconfdir=/etc' '--with-includearch-dir=/usr/include/x86_64-linux-gnu/' '--mandir=/usr/share/man' '--infodir=/usr/share/info' '--with-modules' '--with-gs-font-dir=/usr/share/fonts/type1/gsfonts' '--with-magick-plus-plus' '--with-djvu' '--with-heic' '--with-openjp2' '--with-webp' '--with-wmf' '--without-gvc' '--enable-shared' '--without-dps' '--without-fpx' '--with-perl' '--with-perl-options=INSTALLDIRS=vendor' '--x-includes=/usr/include/X11' '--x-libraries=/usr/lib/X11' '--without-rsvg' '--cache-file=../../config.cache' '--without-gcc-arch' '--disable-silent-rules' '--with-quantum-depth=16' '--enable-hdri=no' 'build_alias=x86_64-linux-gnu' 'CFLAGS=-g -O2 -fdebug-prefix-map=/build/imagemagick-gtb5on/imagemagick-6.9.10.23+dfsg=. -fstack-protector-strong -Wformat -Werror=format-security' 'LDFLAGS=-Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,--as-needed' 'CPPFLAGS=-Wdate-time -D_FORTIFY_SOURCE=2' 'CXXFLAGS=-g -O2 -fdebug-prefix-map=/build/imagemagick-gtb5on/imagemagick-6.9.10.23+dfsg=. -fstack-protector-strong -Wformat -Werror=format-security'
CONFIGURE_PATH /etc/ImageMagick-6/
COPYRIGHT      Copyright (C) 1999-2019 ImageMagick Studio LLC
CPPFLAGS       -I/usr/include/ImageMagick-6
CXX            g++
CXXFLAGS       -g -O2 -fdebug-prefix-map=/build/imagemagick-gtb5on/imagemagick-6.9.10.23+dfsg=. -fstack-protector-strong -Wformat -Werror=format-security -pthread
DEFS           -DHAVE_CONFIG_H
DELEGATES      bzlib djvu mpeg fftw fontconfig freetype jbig jng jpeg lcms lqr lzma openexr pango png ps tiff webp wmf x xml zlib
DISTCHECK_CONFIG_FLAGS 'CFLAGS=-g -O2 -fdebug-prefix-map=/build/imagemagick-gtb5on/imagemagick-6.9.10.23+dfsg=. -fstack-protector-strong -Wformat -Werror=format-security' 'CPPFLAGS=-Wdate-time -D_FORTIFY_SOURCE=2' 'LDFLAGS=-Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,--as-needed'  --disable-deprecated  --with-quantum-depth=16  --with-jemalloc=no  --with-umem=no  --with-autotrace=no  --with-dps=no  --with-fpx=no  --with-gslib=no  --with-fontpath=  --with-gs-font-dir=/usr/share/fonts/type1/gsfonts  --with-gvc=no  --with-rsvg=no 
DOCUMENTATION_PATH /usr/share/doc/imagemagick-6-common/html
EXEC-PREFIX    /usr
EXECUTABLE_PATH /usr/bin
FEATURES       DPC Cipher OpenMP Modules
FILTER_PATH    /usr/lib/x86_64-linux-gnu/ImageMagick-6.9.10/modules-Q16/filters
GIT_REVISION   14107
HOST           x86_64-pc-linux-gnu
INCLUDE_PATH   /usr/include/ImageMagick-6
LDFLAGS        -L/usr/lib/x86_64-linux-gnu -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,--as-needed  -L/usr/lib/X11
LIB_VERSION    0x69A
LIB_VERSION_NUMBER 6,9,10,23
LIBRARY_PATH   /usr/lib/x86_64-linux-gnu/ImageMagick-6.9.10
LIBS            -llcms2 -lfreetype  -llqr-1 -lglib-2.0 -lfftw3  -lxml2 -lfontconfig -lfreetype -lXext   -lSM -lICE -lX11  -lXt -llzma -lbz2 -lz  -lltdl   -lm     -lgomp
NAME           ImageMagick
PCFLAGS        -fopenmp -DMAGICKCORE_HDRI_ENABLE=0 -DMAGICKCORE_QUANTUM_DEPTH=16
PREFIX         /usr
QuantumDepth   16
RELEASE_DATE   20190101
SHARE_PATH     /usr/share/ImageMagick-6
SHAREARCH_PATH /usr/lib/x86_64-linux-gnu/ImageMagick-6.9.10/config-Q16
TARGET_CPU     x86_64
TARGET_OS      linux-gnu
TARGET_VENDOR  pc
VERSION        6.9.10
WEBSITE        https://imagemagick.org

Path: [built-in]

Name           Value
-------------------------------------------------------------------------------
FEATURES       OpenMP 
NAME           ImageMagick
QuantumDepth   16

Interestingly, when I added a system command to do the same thing in C code I get following error

identify: symbol lookup error: /snap/core20/current/lib/x86_64-linux-gnu/libpthread.so.0: undefined symbol: __libc_pthread_init, version GLIBC_PRIVATE

Can it have something to do with ImageMagick linking errors?

0

There are 0 best solutions below