tesseract: Linux support missing for .NET Core
When trying to run minimal application on linux, exception is thrown
System.DllNotFoundException: Failed to find library "libleptonica-1.78.0.so" for platform x64
So native dependencies aren’t included for any platforms other than Windows it seems.
About this issue
- Original URL
- State: open
- Created 4 years ago
- Reactions: 12
- Comments: 45 (2 by maintainers)
Links to this issue
Commits related to this issue
- Fix tesseract not working in docker deploymet See: https://github.com/charlesw/tesseract/issues/503#issuecomment-1816048426 — committed to Devil7-Softwares/TNEB-Shutdown-Notifier by Devil7DK 6 months ago
Wouldn’t it make more sense to just bundle the native dependencies in the package? There are many .net packages that do this rather than requiring that people have exactly the right libs installed (or perform manual steps to copy in those dependencies).
This worked fo me in Dockerfile. We had to build libtesseract.so.4.0.1 from source RUN apt-get update && apt-get install -y libleptonica-dev RUN apt-get update && apt-get install -y libtesseract-dev RUN apt-get update && apt-get install -y libc6-dev RUN apt-get update && apt-get install -y libjpeg62-turbo-dev RUN apt-get update && apt-get install -y libgdiplus
WORKDIR /app/x64 RUN ln -s /usr/lib/x86_64-linux-gnu/liblept.so.5 liblept.so.5 RUN ln -s /usr/lib/x86_64-linux-gnu/liblept.so.5 libleptonica-1.80.0.so COPY ./sofile/libtesseract.so.4.0.1 libtesseract41.so
This is how I fixed it in a Debian 9 server:
The paths and versions might be different in your machine.
I’ve put pre-built
tesseract
andleptonica
libraries for Linux-x64 with no external dependencies in our IsIdentifiable project, which uses Tesseract; the files are here https://github.com/SMI/IsIdentifiable/tree/main/IsIdentifiable/runtimes/linux-x64/native along with a workaround for loading issues (glibc movingdlopen
and related functions fromlibdl.so
tolibc.so
which broke InteropDotNet as embedded in this Tesseract wrapper, plus the reliance onGetExecutingAssembly
which doesn’t function on single-file builds): https://github.com/SMI/IsIdentifiable/blob/main/IsIdentifiable/TesseractLinuxLoaderFix.csThe problem is that InteropDotNet seems to expect native libleptonica and libtesseract in the according folder (x64 or x86). So if you’re lazy as myself, you can install
libtesseract-dev
andlibleptonica-dev
, copy the *.so files to bin/< Configuration >/netcoreapp3.1/x64 folder, rename them (compiler will you what file is missing) and it suddenly works. Assuming your distro’s software sources contain the proper versions, that is 😉I think the appropriate solution though is to ship the binaries for Linux as it’s done for Windows.
I was thinking a better way of dealing with this would be to support falling back on just using the generic load dynamic library routine (i.e. standard search paths). That way it should just work provided the libraries been installed.
Only issue I can think of is it might cause issues with the diagnosing errors relating to finding or loading the library. Which has been a consistent pain in the ass.
How does that sound?
On Tue, 28 Jan 2020, 07:13 Arthur, notifications@github.com wrote:
Monday morning, fresh coffee, clear mind, I finally got this to work! My Leptonica and Tesseract compilation weren’t correct, I fixed this, and there also was some missing dependencies in my Docker image, now everything is sorted out and working as it should!
I compiled following working Dockerfile, maybe this helps someone to save some hours of trial-and-error 😃 https://stackoverflow.com/a/71066165/4244096
thanks. i’ve added the file to my x64 directory and named it libtesseract41.so but i’m still getting the dll not found exception
On Fri, 2 Jul 2021 at 08:54, howff @.***> wrote:
It’s very useful to me ,thanks
Even with the libleptonica-1.80.0.so inside the x64 folder it still has an error
I use wrapper for .NET 4.1.1 and it worked on WSL2 (Ubuntu 20.04) using solution by carloswbarros . But deploing on Docker on AWS it fails with message Failed to find library “libleptonica-1.80.0.so” for platform x64. or sometimes with Failed to find library “libtesseract41.so” for platform x64. I tryied symlinks like WORKDIR /app/x64 RUN ln -s /usr/lib/x86_64-linux-gnu/liblept.so.5 libleptonica-1.80.0.so RUN ln -s /usr/lib/x86_64-linux-gnu/libtesseract.so.4.0.1 libtesseract41.so an it does not help. Also I tried to copy to x64 folder directly from solution folder and same result. Now I think that I have to compile it may be. Actually it is a good idea to have linux library with nuget package installed.
Thanks a lot for trying to help me with this, basically, in my Docker image I have this:
And this:
Which is consistent with what I got from ldd:
However, even with this configuration, I still get the
System.DllNotFoundException: Failed to find library "libleptonica-1.78.0.so" for platform x64.
which drives me crazy.