ccouzens / tesseract-sys

Rust FFI bindings to tesseract
MIT License
26 stars 18 forks source link

Unable to compile on mac os Catalina 10.15.7 #4

Closed magom001 closed 3 years ago

magom001 commented 3 years ago

During compilation

   Compiling thiserror v1.0.22
   Compiling leptonica-sys v0.3.3
   Compiling tesseract-sys v0.5.4
error: failed to run custom build command for `tesseract-sys v0.5.4`

Caused by:
  process didn't exit successfully: `/Users/a18678299/Documents/test-rc/target/debug/build/tesseract-sys-04ae1979553eebf3/build-script-build` (exit code: 101)
  --- stdout
  cargo:rustc-link-lib=tesseract

  --- stderr
  /usr/local/include/tesseract/publictypes.h:33:1: error: unknown type name 'constexpr'
  /usr/local/include/tesseract/publictypes.h:38:1: error: unknown type name 'constexpr'
  /usr/local/include/tesseract/publictypes.h:40:1: error: unknown type name 'constexpr'
  /usr/local/include/tesseract/publictypes.h:45:1: error: unknown type name 'constexpr'
  /usr/local/include/tesseract/publictypes.h:33:1: error: unknown type name 'constexpr', err: true
  /usr/local/include/tesseract/publictypes.h:38:1: error: unknown type name 'constexpr', err: true
  /usr/local/include/tesseract/publictypes.h:40:1: error: unknown type name 'constexpr', err: true
  /usr/local/include/tesseract/publictypes.h:45:1: error: unknown type name 'constexpr', err: true
  thread 'main' panicked at 'Unable to generate public types bindings: ()', /Users/a18678299/.cargo/registry/src/github.com-1ecc6299db9ec823/tesseract-sys-0.5.4/build.rs:68:10
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

I am not an expert on rust. But how come it does not understand constexpr?

ccouzens commented 3 years ago

Hi @magom001

On my Mac Laptop (also Catalina 10.15.7), I see the same error. It used to work.

I think the version of clang might have been updated recently on Mac to Apple clang version 12.0.0 (clang-1200.0.32.28).

I'm using the brew package manager. I can install clang 11 using it.

brew install llvm tesseract leptonica

Then, I can build tesseract-sys using a couple extra environment variables:

PATH="/usr/local/opt/llvm/bin:$PATH" BINDGEN_EXTRA_CLANG_ARGS='-I"/usr/local/Cellar/tesseract/4.1.1/include" -I"/usr/local/Cellar/leptonica/1.80.0/include"' cargo test

Does that work for you?

But how come it does not understand constexpr?

I think this may be an issue with how the bindgen crate interacts with clang. Maybe clang 12 is too new, and it will be fixed in an update of bindgen.

magom001 commented 3 years ago

Thanks for your feedback! Indeed it does work with clang 11

TOML

[package]
name = "tess-build"

[dependencies]
tesseract = "0.6.2"

main.rs

fn main() {
    let text = tesseract::ocr("<PATH_TO_DIR>/tess-build/img.png", "eng").unwrap();
    println!("{}", text);
}

running with

PATH="/usr/local/opt/llvm/bin:$PATH" BINDGEN_EXTRA_CLANG_ARGS='-I"/usr/local/Cellar/tesseract/4.1.1/include" -I"/usr/local/Cellar/leptonica/1.80.0/include"' cargo run
ccouzens commented 3 years ago

Good that it worked :+1:

I'll try an issue about it clang 12 and constexpr on the bindgen project.

matthewleon commented 3 years ago

As I've mentioned in the related issue https://github.com/rust-lang/rust-bindgen/issues/1948 this is still failing in the same way on clang 13.