-->

Error setting up the tesseract OCR in gem in rails

2020-07-25 01:36发布

问题:

I'm trying to setup the tesseract-ocr gem in my rails environment. I have ran brew install tesseract and then ran a bundle install on the app and that all runs without errors however when starting the app (rails s) the following error is throw:

/Users/xxxx/.rvm/gems/ruby-1.9.2-p290@xxxx/gems/ffi-inline-0.0.4.3/lib/ffi/inline/compilers/gcc.rb:35:in `compile': compile error: see logs at /var/folders/66/pm_j0lp94gvcj0qnlcnsx9pw0000gn/T/.ffi-inline-501/4239dac38f2a721e0dc5b3750d71ce2e6fa4acb6.log (CompilationError)

It reference the following log file:

g++ -dynamic -bundle -fPIC  -L/usr/local/Cellar/tesseract/3.02.02/lib -I/usr/local/Cellar/tesseract/3.02.02/include -o /var/folders/66/pm_j0lp94gvcj0qnlcnsx9pw0000gn/T/.ffi-inline-501/4239dac38f2a721e0dc5b3750d71ce2e6fa4acb6.dylib /var/folders/66/pm_j0lp94gvcj0qnlcnsx9pw0000gn/T/.ffi-inline-501/4239dac38f2a721e0dc5b3750d71ce2e6fa4acb6.cpp -llept 2>>/var/folders/66/pm_j0lp94gvcj0qnlcnsx9pw0000gn/T/.ffi-inline-501/4239dac38f2a721e0dc5b3750d71ce2e6fa4acb6.log
/var/folders/66/pm_j0lp94gvcj0qnlcnsx9pw0000gn/T/.ffi-inline-501/4239dac38f2a721e0dc5b3750d71ce2e6fa4acb6.cpp:1:10: fatal error: 'leptonica/allheaders.h' file not found
#include <leptonica/allheaders.h>

I followed these two issues: https://github.com/meh/ruby-tesseract-ocr/issues/3 and https://github.com/meh/ruby-tesseract-ocr/issues/21

It talks about setting ENV vars which i have done. I created a test.rb file in the initalizers folder with the following vars set:

ENV['CFLAGS'] = '-I/usr/local/Cellar/tesseract/3.02.02/include' 
ENV['LDFLAGS'] = '-L/usr/local/Cellar/tesseract/3.02.02/lib'

However this makes no difference to the error when starting the app.

I don't understand what it means when it says update the headers. I was wondering if someone could tell me exactly what to do to get this working.

Thanks.

回答1:

Also had the same error. I solved it by installing the dev packages for tesseract and leptonica.

For debian based systems

sudo apt-get install libleptonica-dev libtesseract-dev

For redhat base systems

sudo yum insall leptonica-devel tesseract-devel

That solved the problem for me.



回答2:

I've fixed this...

Just in case anyone else has a problem here's exactly how it was fixed in mine:

Firstly had to run both:

brew install tesseract

and

brew install leptonica

Then in the Gemfile NOT in an initializer you have to put both paths to the libraries as env vars:

ENV['CFLAGS'] = '-I/usr/local/Cellar/tesseract/3.02.02/include -I/usr/local/Cellar/leptonica/1.69/include' 
ENV['LDFLAGS'] = '-L/usr/local/Cellar/tesseract/3.02.02/lib -L/usr/local/Cellar/leptonica/1.69/lib'


回答3:

Had this issue (OS X El Capitan). Fixed by downgrading tesseract with

brew uninstall --force tesseract
brew install https://raw.githubusercontent.com/Homebrew/homebrew/8ba134eda537d2cee7daa7ebdd9f728389d9c53e/Library/Formula/tesseract.rb

and updating xcode

xcode-select --install