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)

Commits related to this issue

Most upvoted comments

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:

cd ~/MyProject/x64

sudo apt install libleptonica-dev
ln -s /usr/lib/x86_64-linux-gnu/liblept.so.5 liblept.so.5
ln -s /usr/lib/x86_64-linux-gnu/liblept.so.5 libleptonica-1.78.0.so

# Installed the repository from https://notesalexp.org/
sudo apt install libtesseract-dev
ln -s /usr/lib/x86_64-linux-gnu/libtesseract.so.4.0.1 libtesseract41.so

The paths and versions might be different in your machine.

I’ve put pre-built tesseract and leptonica 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 moving dlopen and related functions from libdl.so to libc.so which broke InteropDotNet as embedded in this Tesseract wrapper, plus the reliance on GetExecutingAssembly which doesn’t function on single-file builds): https://github.com/SMI/IsIdentifiable/blob/main/IsIdentifiable/TesseractLinuxLoaderFix.cs

The 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 and libleptonica-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:

The problem is that InteropDotNet https://github.com/AndreyAkinshin/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 and libleptonica-dev, copy the *.so files to bin//x64 folder, rename them (compiler will you what file is missing) and it suddenly works.

I think the appropriate solution though is to ship the binaries for Linux as it’s done for Windows.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/charlesw/tesseract/issues/503?email_source=notifications&email_token=AAB7HSFBQGRE4KQQXT532Q3Q7455HA5CNFSM4KKGHXW2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEKA4R5A#issuecomment-578930932, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAB7HSDQUHSMSOEPC36WOSDQ7455HANCNFSM4KKGHXWQ .

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:

One of the previous comments has a link to pre-compiled libraries here: https://github.com/SMI/SmiServices/tree/master/lib and an explanation of how to rename them.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/charlesw/tesseract/issues/503#issuecomment-872797622, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGML6N3UQTTJ5IAJBCOB25TTVVWDVANCNFSM4KKGHXWQ .

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

It’s very useful to me ,thanks

Even with the libleptonica-1.80.0.so inside the x64 folder it still has an error

Files_LIB

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:

root@st-ocr_service:/usr/local/lib# ls -alh
total 145M
drwxr-xr-x 1 root root 4.0K Feb  7 15:51 .
drwxr-xr-x 1 root root 4.0K Feb  7 15:51 ..
-rw-r--r-- 1 root root  17M Feb  7 14:14 liblept.a
-rwxr-xr-x 1 root root  984 Feb  7 14:14 liblept.la
lrwxrwxrwx 1 root root   16 Feb  7 14:14 liblept.so -> liblept.so.5.0.3
lrwxrwxrwx 1 root root   16 Feb  7 14:14 liblept.so.5 -> liblept.so.5.0.3
-rwxr-xr-x 1 root root 2.6M Feb  7 14:14 liblept.so.5.0.3
-rw-r--r-- 1 root root 123M Feb  7 14:19 libtesseract.a
-rwxr-xr-x 1 root root 1.1K Feb  7 14:19 libtesseract.la
lrwxrwxrwx 1 root root   21 Feb  7 14:19 libtesseract.so -> libtesseract.so.4.0.1
lrwxrwxrwx 1 root root   21 Feb  7 14:19 libtesseract.so.4 -> libtesseract.so.4.0.1
-rwxr-xr-x 1 root root 3.4M Feb  7 14:19 libtesseract.so.4.0.1
drwxr-xr-x 2 root root 4.0K Feb  7 15:51 pkgconfig

And this:

root@st-ocr_service:/app/x64# ls -alh
total 12K
drwxr-xr-x 1 root root 4.0K Feb  7 16:08 .
drwxr-xr-x 1 root root 4.0K Feb  7 15:51 ..
lrwxrwxrwx 1 root root   27 Feb  7 16:03 liblept.so.5 -> /usr/local/lib/liblept.so.5
lrwxrwxrwx 1 root root   27 Feb  7 16:08 libleptonica-1.78.0.so -> /usr/local/lib/liblept.so.5
lrwxrwxrwx 1 root root   36 Feb  7 16:08 libtesseract41.so -> /usr/local/lib/libtesseract.so.4.0.1

Which is consistent with what I got from ldd:

root@st-ocr_service:/app/x64# ldd libtesseract41.so 
	[...]
	liblept.so.5 => /usr/local/lib/liblept.so.5 (0x00007fe735ff6000)
	[...]

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.