Sicos1977 / TesseractOCR

A .net library to work with Google's Tesseract
161 stars 20 forks source link

System.DllNotFoundException: Failed to find library 'tesseract53.dll' for platform x64 #45

Closed kzorin52 closed 10 months ago

kzorin52 commented 11 months ago

I decided to build tesseract by myself, patched w/o logging: image

so i just copy result x64 dll to x64 folder in binaries (replaced original) and gets this error:

Unhandled exception. System.TypeInitializationException: The type initializer for 'PrivateParser.FileProviders.AllFileProviders' threw an exception.
 ---> System.TypeInitializationException: The type initializer for 'PrivateParser.FileProviders.ImageFile' threw an exception.
 ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
 ---> System.DllNotFoundException: Failed to find library 'tesseract53.dll' for platform x64
   at TesseractOCR.InteropDotNet.LibraryLoader.LoadLibrary(String fileName, String platformName)
   at InteropRuntimeImplementer.TessApiSignaturesInstance.TessApiSignaturesImplementation..ctor(LibraryLoader loader)
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodBaseInvoker.InvokeDirectByRefWithFewArgs(Object obj, Span`1 copyOfArgs, BindingFlags invokeAttr)
   --- End of inner exception stack trace ---
   at System.Reflection.MethodBaseInvoker.InvokeDirectByRefWithFewArgs(Object obj, Span`1 copyOfArgs, BindingFlags invokeAttr)
   at System.Reflection.MethodBaseInvoker.InvokeWithOneArg(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture)   at System.Activator.CreateInstance(Type type, Object[] args)
   at TesseractOCR.InteropDotNet.InteropRuntimeImplementer.CreateInstance[T]()
   at TesseractOCR.Interop.TessApi.Initialize()
   at TesseractOCR.Interop.TessApi.get_Native()
   at TesseractOCR.Engine.Initialize(String dataPath, String languages, EngineMode engineMode, IEnumerable`1 configFiles, IDictionary`2 initialValues, Boolean setOnlyNonDebugVariables, ILogger logger)
   at TesseractOCR.Engine..ctor(String dataPath, String languages, EngineMode engineMode, IEnumerable`1 configFiles, IDictionary`2 initialValues, Boolean setOnlyNonDebugVariables, ILogger logger)
Sicos1977 commented 11 months ago

Please run the code with logging so that it tells you where it is looking for the DLL.

kzorin52 commented 11 months ago

Please run the code with logging so that it tells you where it is looking for the DLL.

2023-10-24T15:39:28.745 - Trying to load native function 'boxaGetBox' from the library with handle '140736763592704'
2023-10-24T15:39:28.746 - Successfully loaded native function 'boxaGetBox' with handle '140736763804848'
2023-10-24T15:39:28.746 - Trying to load native function 'boxGetGeometry' from the library with handle '140736763592704'2023-10-24T15:39:28.747 - Successfully loaded native function 'boxGetGeometry' with handle '140736763801776'
2023-10-24T15:39:28.747 - Trying to load native function 'boxDestroy' from the library with handle '140736763592704'
2023-10-24T15:39:28.747 - Successfully loaded native function 'boxDestroy' with handle '140736763801680'
2023-10-24T15:39:28.747 - Trying to load native function 'boxaDestroy' from the library with handle '140736763592704'
2023-10-24T15:39:28.748 - Successfully loaded native function 'boxaDestroy' with handle '140736763803328'
2023-10-24T15:39:28.748 - Trying to load native function 'pixBlend' from the library with handle '140736763592704'
2023-10-24T15:39:28.748 - Successfully loaded native function 'pixBlend' with handle '140736763770000'
2023-10-24T15:39:28.763 - Current platform is x64
2023-10-24T15:39:28.763 - Code base was empty
2023-10-24T15:39:28.764 - Executing assembly location was empty
2023-10-24T15:39:28.765 - Trying to load file from 'F:\repos\PrivateParser\bin\x64\Release\net8.0-windows\x64\tesseract53.dll'
2023-10-24T15:39:28.766 - Trying to load native library 'F:\repos\PrivateParser\bin\x64\Release\net8.0-windows\x64\tesseract53.dll'
2023-10-24T15:39:28.768 - Failed to load native library 'F:\repos\PrivateParser\bin\x64\Release\net8.0-windows\x64\tesseract53.dll', set logging to debug level and check logging
2023-10-24T15:39:28.768 - Trying to load file from 'F:\repos\PrivateParser\bin\x64\Release\net8.0-windows\x64\tesseract53.dll'
2023-10-24T15:39:28.769 - Trying to load native library 'F:\repos\PrivateParser\bin\x64\Release\net8.0-windows\x64\tesseract53.dll'
2023-10-24T15:39:28.770 - Failed to load native library 'F:\repos\PrivateParser\bin\x64\Release\net8.0-windows\x64\tesseract53.dll', set logging to debug level and check logging
2023-10-24T15:39:28.771 - Custom search path is not defined, skipping.
2023-10-24T15:39:28.771 - Failed to find library 'tesseract53.dll' for platform x64
Sicos1977 commented 11 months ago

It finds the file but can not load it so either you did compile it as x64 and try to load it as 32 bits (or the other way around) or something is just wrong with the DLL.

So do what it asks --> set logging to debug level and check logging

kzorin52 commented 11 months ago

It finds the file but can not load it so either you did compile it as x64 and try to load it as 32 bits (or the other way around) or something is just wrong with the DLL.

So do what it asks --> set logging to debug level and check logging

How to set debug level? I already tried x86, same result So i compiled x64 tesseract

kzorin52 commented 11 months ago

I checked up, there is already debug level:

Writes log information to console at the <see cref="LogLevel.Debug"/>, <see cref="LogLevel.Error"/>
and <see cref="LogLevel.Information"/> <see cref="LogLevel"/>
 Engine Engine = new(".", "eng", EngineMode.LstmOnly, logger: new TesseractOCR.Loggers.Console())
kzorin52 commented 11 months ago

Full log from debug logs: https://pastebin.com/FEm5sbrg

Sicos1977 commented 11 months ago

According to the logging something is wrong with the DLL you compiled. According to the logging it is in --> F:\repos\PrivateParser\bin\Release\net8.0-windows\x64\tesseract53.dll but it could not be loaded so I guess you did something wrong when compiling the DLL. It is hard for me to just guess what is wrong.

kzorin52 commented 11 months ago

Okay, ill recompile full stock, w/o any patches

ibrahim324 commented 6 months ago

How do i build on macos M2 chips? I get this error when using the script out of the wiki:

error: in triplet x64-windows-static: Use of Visual Studio's Developer Prompt is unsupported on non-Windows hosts.
Define 'VCPKG_CMAKE_SYSTEM_NAME' or 'VCPKG_CHAINLOAD_TOOLCHAIN_FILE' in the triplet file.

My logs are:

2024-03-24T01:38:07.241 - Current OS is MacOSX
2024-03-24T01:38:07.287 - Current platform is x64
2024-03-24T01:38:07.287 - Trying to load file from 'Users/halilibrahimozcan/source/projects/Ocr/Ocr/bin/Debug/net8.0/x64/libleptonica-1.83.1.dll.dylib'
2024-03-24T01:38:07.287 - Trying to load file from '/Users/halilibrahimozcan/source/projects/Ocr/Ocr/bin/Debug/net8.0/x64/libleptonica-1.83.1.dll.dylib'
2024-03-24T01:38:07.287 - Trying to load file from '/Users/halilibrahimozcan/source/projects/Ocr/Ocr/bin/Debug/net8.0/x64/libleptonica-1.83.1.dll.dylib'
2024-03-24T01:38:07.287 - Trying to load file from '/Users/halilibrahimozcan/source/projects/Ocr/Ocr/bin/Debug/net8.0/x64/libleptonica-1.83.1.dll.dylib'
2024-03-24T01:38:07.288 - Custom search path is not defined, skipping.
2024-03-24T01:38:07.288 - Failed to find library 'libleptonica-1.83.1.dll.dylib' for platform x64