houqp / leptess

Productive and safe Rust binding for leptonica and tesseract
https://houqp.github.io/leptess/leptess/index.html
MIT License
258 stars 29 forks source link

Unable to generate public types bindings #32

Closed rafaelcaricio closed 3 years ago

rafaelcaricio commented 3 years ago

I'm trying to use this crate in my project and I get an error from the bindings generation from tesseract-sys:

error: failed to run custom build command for `tesseract-sys v0.5.5`

Caused by:
  process didn't exit successfully: `/Users/rafael/myproject/target/debug/build/tesseract-sys-b2dc871cdb8dbd4c/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/rafael/.cargo/registry/src/github.com-1ecc6299db9ec823/tesseract-sys-0.5.5/build.rs:68:10
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...
error: build failed

This is the version of tesseract I have installed:

tesseract 4.1.1
 leptonica-1.80.0
  libgif 5.2.1 : libjpeg 9d : libpng 1.6.37 : libtiff 4.2.0 : zlib 1.2.11 : libwebp 1.2.0 : libopenjp2 2.4.0
 Found AVX2
 Found AVX
 Found FMA
 Found SSE

Do you have any pointers to what might be happening?

ccouzens commented 3 years ago

Hi @rafaelcaricio ,

I think you're hitting this issue

https://github.com/ccouzens/tesseract-sys/issues/4

which has been reported to rust-bindgen here: https://github.com/rust-lang/rust-bindgen/issues/1948

If I remember correctly the issue comes from the current Mac version of clang being weird.

The solution (if you're happy to use brew) is to install brew's clang

brew install llvm tesseract leptonica

And then you need to set a couple environment variables before running your build:

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

Hope that helps,

Chris

rafaelcaricio commented 3 years ago

@ccouzens It worked for me, thank you! 🙏