Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libleptonica-1.82.0.so on X86 - Exception #633

Open
Genko71 opened this issue Feb 10, 2023 · 7 comments
Open

libleptonica-1.82.0.so on X86 - Exception #633

Genko71 opened this issue Feb 10, 2023 · 7 comments

Comments

@Genko71
Copy link

Genko71 commented Feb 10, 2023

Hi to all,
i'm executing one of the example for tesseract, i've compiled the source and put it in the assembly of the main project of the solution.
debugging step by step this code :

        string testImagePath = "C:/Projects/Images/Grab.JPG";
        string configurationFilePath = @"./tessdata";
        using (var engine = new TesseractEngine(configurationFilePath, "eng", EngineMode.Default))
        {
            using (var img = Pix.LoadFromFile(testImagePath))
            {
                using (var page = engine.Process(img))
                {
                    var text = page.GetText();
                    Console.WriteLine("Mean confidence: {0}", page.GetMeanConfidence());

                    Console.WriteLine("Text (GetText): \r\n{0}", text);
                    Console.WriteLine("Text (iterator):");
                }
            }
        }

at this point : using (var engine = new TesseractEngine(configurationFilePath, "eng", EngineMode.Default))

i see that in this part of the code of tesseract (LibraryLoader of InteropDotNet.cs)

    public IntPtr LoadLibrary(string fileName, string platformName = null)
    {            
        fileName = FixUpLibraryName(fileName);
        lock (syncLock)
        {
            if (!loadedAssemblies.ContainsKey(fileName))
            {
                if (platformName == null)
                    platformName = SystemManager.GetPlatformName();
                
                Logger.TraceInformation("Current platform: " + platformName);
                                    
                IntPtr dllHandle = CheckCustomSearchPath(fileName, platformName);
                if (dllHandle == IntPtr.Zero)
                    dllHandle = CheckExecutingAssemblyDomain(fileName, platformName);
                if (dllHandle == IntPtr.Zero)
                    **dllHandle = CheckCurrentAppDomain(fileName, platformName);**
                if (dllHandle == IntPtr.Zero)
                    dllHandle = CheckCurrentAppDomainBin(fileName, platformName);
                if (dllHandle == IntPtr.Zero)
                    dllHandle = CheckWorkingDirecotry(fileName, platformName);

                if (dllHandle != IntPtr.Zero)
                    loadedAssemblies[fileName] = dllHandle;
                else
                    throw new DllNotFoundException(string.Format("Failed to find library \"{0}\" for platform {1}.", fileName, platformName));
            }

            return loadedAssemblies[fileName];
        }
    }

the debug show me this information when it reach the comand in Bold (dllHandle = CheckCurrentAppDomain(fileName, platformName);)
image

and executing it, it gives me back this error:

image

the $exception.InnerException.Message contains this description : "Failed to find library "libleptonica-1.82.0.so" for platform x86."

Could you please help me?

Many thanks in advance.
Massimo

@iongion
Copy link

iongion commented Feb 16, 2023

If of any use - there is no libleptonica-1.82.0.so - on linux it has different naming conventions

ls -all /usr/local/lib

.rw-r--r--  13M root root 2023-02-16 08:38 liblept.a
.rwxr-xr-x 1.0k root root 2023-02-16 08:38 liblept.la
lrwxrwxrwx   16 root root 2023-02-16 08:38 liblept.so -> liblept.so.5.0.4
lrwxrwxrwx   16 root root 2023-02-16 08:38 liblept.so.5 -> liblept.so.5.0.4
.rwxr-xr-x 9.1M root root 2023-02-16 08:38 liblept.so.5.0.4
.rw-r--r--  13M root root 2023-02-16 08:23 libleptonica.a
.rwxr-xr-x 1.0k root root 2023-02-16 08:23 libleptonica.la
lrwxrwxrwx   21 root root 2023-02-16 08:23 libleptonica.so -> libleptonica.so.6.0.0
lrwxrwxrwx   21 root root 2023-02-16 08:23 libleptonica.so.6 -> libleptonica.so.6.0.0
.rwxr-xr-x 9.1M root root 2023-02-16 08:23 libleptonica.so.6.0.0

@iongion
Copy link

iongion commented Feb 16, 2023

Attempt of a dirty fix, copied one of those as libleptonica-1.82.0.so and then another one pops

 ---> System.DllNotFoundException: Unable to load shared library 'libdl' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: liblibdl: cannot open shared object file: No such file or directory

Of course I am doing it wrong, that's not the way it should work

System.DllNotFoundException: Unable to load shared library 'libdl' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: liblibdl: cannot open shared object file: No such file or directory
   at InteropDotNet.UnixLibraryLoaderLogic.UnixGetLastError()
   at InteropDotNet.UnixLibraryLoaderLogic.LoadLibrary(String fileName)
   at InteropDotNet.LibraryLoader.InternalLoadLibrary(String baseDirectory, String platformName, String fileName)
   at InteropDotNet.LibraryLoader.CheckExecutingAssemblyDomain(String fileName, String platformName)
   at InteropDotNet.LibraryLoader.LoadLibrary(String fileName, String platformName)

Copied them all to bin/Debug/net6.0 and it works

image

@Genko71
Copy link
Author

Genko71 commented Feb 16, 2023

Hi Iongion,
i've talk with Charles regarding this issue, andit's very strange.
I'm working on a genuine Microsoft windows 10 pro as you can see below.

image

The code try to get (i've seen with debug) the right OS, but instead it gets Unix system....
So it tries to elaborates and load libraries as unix, instead of loading the leptonica-1.82.0.dll.
Anyway, i've tried to force the code to take the Windows OS road instead that unix, but i get an exception due to a null value received from this part of code, especially from the two process (CheckCurrentAppDomainBin,CheckCurrentAppDomain)

            if (!loadedAssemblies.ContainsKey(fileName))
            {
                if (platformName == null)
                    platformName = SystemManager.GetPlatformName();
                
                Logger.TraceInformation("Current platform: " + platformName);
                                    
                IntPtr dllHandle = CheckCustomSearchPath(fileName, platformName);
                if (dllHandle == IntPtr.Zero)
                    dllHandle = CheckExecutingAssemblyDomain(fileName, platformName);
                if (dllHandle == IntPtr.Zero)
                    **dllHandle = CheckCurrentAppDomain(fileName, platformName);**
                if (dllHandle == IntPtr.Zero)
                    **dllHandle = CheckCurrentAppDomainBin(fileName, platformName);**
                if (dllHandle == IntPtr.Zero)
                    dllHandle = CheckWorkingDirecotry(fileName, platformName);

                if (dllHandle != IntPtr.Zero)
                    loadedAssemblies[fileName] = dllHandle;
                else
                    throw new DllNotFoundException(string.Format("Failed to find library \"{0}\" for platform {1}.", fileName, platformName));
            }

            return loadedAssemblies[fileName];

I've also tried to set the CheckCustomSearchPath (with a directory inside the project on my PC), but i always receive that the file is not present...

Many thanks for the help.
Genko

@charlesw
Copy link
Owner

charlesw commented Feb 16, 2023 via email

@Genko71
Copy link
Author

Genko71 commented Feb 17, 2023

I've another machine in my home with this OS.

image

i've enabled xamarin for VS2019 and activated HAXM Hyper-V, download and installed .net sdk 4.7 and 4.8 as requested.
I've created the emulator in VS2019 as show below.

image

And the code give me back again Unix as OS, when i reach with the debug this point.

image

I've also request support on MSDN Forum and i've received this answer.

that is because the android os is linux, and your code is running in a android emulator (linux virtual machine).

Maybe i'm doing somethings wrong?

Thanks.
Genko

@charlesw
Copy link
Owner

charlesw commented Feb 17, 2023 via email

@Genko71
Copy link
Author

Genko71 commented Feb 17, 2023

OK,
but the others who run the application on Windows OS, how do they debug the code, if they don't use the Android emulator (Linux VM)?
What I mean is, how do others who use your wrapper on Windows systems test it if then in debug the pointed system is Unix?

Excuse me, but i'm new to the develop of Application on mobile.
I've seen that on VS2019 there are two option in the Visual Studio Installer, perhaps i've installed the wrong one (the one in yellow color), i've to install the one circled in red, or i've to install Android Studio?

image

Many thanks
Genko

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants