nlfiedler / magick-rust

Rust bindings for ImageMagick
https://crates.io/crates/magick_rust
Apache License 2.0
254 stars 68 forks source link

Fail to build #118

Closed worikgh closed 4 months ago

worikgh commented 5 months ago

On Debian 12 I cloned the repository and ran cargo build`

magick-rust$ PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig cargo build

I get the error:

  thread 'main' panicked at build.rs:288:10:
  called `Result::unwrap()` on an `Err` value: 
  pkg-config exited with status code 1
  > PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig PKG_CONFIG_ALLOW_SYSTEM_LIBS=1 PKG_CONFIG_ALLOW_SYSTEM_CFLAGS=1 pkg-config --libs --cflags MagickWand MagickWand >= 7.0

  The system library `MagickWand` required by crate `magick_rust` was not found.
  The file `MagickWand.pc` needs to be installed and the PKG_CONFIG_PATH environment variable must contain its parent directory.
  PKG_CONFIG_PATH contains the following:
      - /usr/lib/x86_64-linux-gnu/pkgconfig

But:

magick-rust$ ls -l /usr/lib/x86_64-linux-gnu/pkgconfig/MagickWand.pc 
lrwxrwxrwx 1 root root 21 Feb 13 09:15 /usr/lib/x86_64-linux-gnu/pkgconfig/MagickWand.pc -> MagickWand-im6.q16.pc
nlfiedler commented 5 months ago

Unless you check out an older version of magick-rust, you will need to use ImageMagick version 7, which basically requires building it from source. Note that in order to load basically any images at all, you will need to install the requisite image libraries (e.g. libjpeg-dev, libpng-dev), otherwise you get the dreaded "failed to read file" error (ImageMagick return codes are 1 (good) or 0 (bad), so no help in debugging issues).

Here is how to get it compiled and tested. Note that this is a fresh install of bookworm in a VM, in which I install all prerequisites, including Rust and the image libraries:

sudo apt-get update
sudo apt-get install build-essential clang curl git pkg-config libjpeg-dev libjpeg-turbo-progs libpng-dev
wget https://imagemagick.org/archive/ImageMagick.tar.gz
tar axf ImageMagick.tar.gz
cd ImageMagick-7.1.1-31/
./configure --with-magick-plus-plus=no --with-perl=no
make
sudo make install
cd ..
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
. .cargo/env
git clone https://github.com/nlfiedler/magick-rust.git
cd magick-rust/
cargo build
cargo test
nlfiedler commented 4 months ago

Added an INSTALL.md guide that provides tested instructions for building on Ubunut Linux. The example above is slightly wrong, at least for Ubuntu 24.04 (replace libjpeg-turbo-progs with libjpeg-dev).