nlfiedler / magick-rust

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

error[E0425]: cannot find value `QuantumRange` in module `bindings` #40

Closed bbigras closed 3 years ago

bbigras commented 6 years ago

I have this error with magick-rust 0.9. 0.8 seems fine.

Windows ImageMagick-7.0.7-31 nightly-x86_64-pc-windows-msvc (default) rustc 1.27.0-nightly (428ea5f6b 2018-05-06)

error[E0425]: cannot find value `QuantumRange` in module `bindings`
   --> C:\Users\bbigras\.cargo\registry\src\github.com-1ecc6299db9ec823\magick_rust-0.9.0\src\wand\magick.rs:337:80
    |
337 |             if bindings::MagickSepiaToneImage(self.wand, threshold * bindings::QuantumRange) == bindings::MagickBooleanType::MagickTrue {
    |
     ^^^^^^^^^^^^ not found in `bindings`

error: aborting due to previous error
nlfiedler commented 6 years ago

The generated bindings can be quite troublesome, I have to admit. I don't have a Windows system to test this, but that may not be the issue. If I can get a Windows VM to test with, I'll give it a try. In the mean time, look for the bindings.rs file and see how QuantumRange is namespaced. Maybe it's getting some additional prefix, as bindgen has a tendency to do different things depending on flags and versions.

bbigras commented 6 years ago

There's no QuantumRange "whole word" in bindings.rs, The only matches are:

extern "C" {
    pub fn GetMagickQuantumRange(arg1: *mut usize) -> *const libc::c_char;
}
extern "C" {
    pub fn MagickGetQuantumRange(arg1: *mut usize) -> *const libc::c_char;
}
vpzomtrrfrt commented 6 years ago

I'm seeing the same issue on my Gentoo system.

gentoo90 commented 5 years ago

Seing the same error with magick_rust-0.10.0.

Gentoo Linux, rustc 1.32.0-nightly (14997d56a 2018-12-05), imagemagick-7.0.8.11, clang-6.0.1, bindgen-0.29.1

WGH- commented 5 years ago

Still happens as of v0.11.0. I'm on Gentoo as well.

captainbland commented 4 years ago

Sorry to exhume this but maybe it'll be helpful: I've come across this error now using Ubuntu 18.04. What happened was I was using a quantum depth of 16 before and the build worked, everything was happy, but I was having some performance issues so I tried re-building ImageMagick with a quantum depth of 8 and hdri disabled, and now I'm getting the "QuantumRange not found in bindings" error when I try to clean/build my application.

This is with ImageMagick 7.0.10-16 and magick_rust 0.14.0, rust 0.45.0-nightly

nlfiedler commented 4 years ago

I see, that would certainly explain why some people see it and others do not. I wish I knew how to deal with this in better way.

captainbland commented 4 years ago

After a little digging I think the problem with this is to do with this issue: https://github.com/rust-lang/rust-bindgen/issues/1585 https://github.com/rust-lang/rust-bindgen/issues/316

You can see a similar cast/define being performed where HDRI is disabled in magick-type.h when defining the QuantumRange type (indentation editorialised somewhat here)

#if (MAGICKCORE_QUANTUM_DEPTH == 8)
  #define MaxColormapSize  256UL
  #define MaxMap  255UL

  #if defined(MAGICKCORE_HDRI_SUPPORT)
    typedef MagickFloatType Quantum;
    #define QuantumRange  255.0
    #define QuantumFormat  "%g"
  #else
    typedef unsigned char Quantum;
    #define QuantumRange  ((Quantum) 255)
    #define QuantumFormat  "%u"
#endif

So I'm just recompiling with quantum size=8 and hdri enabled which, if I'm correct, should give me the QuantumRange type in this library. I'll update here when I've tested it.

Edit: it works

MolotovCherry commented 3 years ago

Had this issue randomly, the patch giving features = ["disable-hdri"] did allow it to compile for me (so thanks for that). Could this be added to the main page for documentation purposes?

Also, MAGICKCORE_HDRI_ENABLE is set accordingly in the bindings. Perhaps it is possible to check and set things according to the value of this.

nlfiedler commented 3 years ago

Sorry it took me a long time to respond to this. I've updated the README file so that this issue is easier resolve, at least with this temporary work-around. Eventually the issue in rust-bindgen will be fixed, and setting the feature flag in your application won't be necessary any more.

I think for now this issue can be closed, since there is a work-around and finally some guidance in the README file.