目前,我尝试DllImport
从框架文件(dylib)中提取一个库。
当前,框架内还有多个其他库文件,这些文件是我要dllimport的库的依赖项。
我实际上有可以导入框架的设置代码,但是当我尝试以某种方式链接到库文件时,我总是得到一个Reason: image not found
在我的AssemblyLoadContext
中,我像这样覆盖了LoadUnmanagedDll
:
protected override IntPtr LoadUnmanagedDll(string unmanagedDllName)
{
if (unmanagedDllName == KernelApiDll)
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
return LoadUnmanagedDllFromPath("CUSTOM_FRAMEWORK_DIR_UNDER_USERS/Frameworks/Nuance-OmniPage-CSDK-RunTime.framework/Versions/A/Libraries/libkernelapi.dylib");
}
// other os stuff
return IntPtr.Zero;
}
有没有一种方法可以正确地在框架内正确加载所有必需的文件?
在示例makefile(用于C代码)中,-rpath将设置为加载库:
OCRLIBPATH = ../Frameworks/Nuance-OmniPage-CSDK-RunTime.framework/Versions/Current/Libraries
OCRLIBS = -L$(OCRLIBPATH) -lkernelapi -lrecapiplus -lrecpdf -Wl,-rpath,$(OCRRUNPATH)
编辑:
这是我得到的全部错误:
System.DllNotFoundException: Unable to load shared library '/REDACTED_PATH/Nuance-OmniPage-CSDK-RunTime.framework/Versions/A/Libraries/libkernelapi.dylib' or one of its dependencies. In order to help diagnose loading problems, consider setting the DYLD_PRINT_LIBRARIES environment variable: dlopen(/REDACTED_PATH/Nuance-OmniPage-CSDK-RunTime.framework/Versions/A/Libraries/libkernelapi.dylib, 1): Library not loaded: @rpath/Nuance-OmniPage-CSDK-RunTime.framework/Versions/A/Libraries/librecdiag.dylib
Referenced from: /REDACTED_PATH/Nuance-OmniPage-CSDK-RunTime.framework/Versions/A/Libraries/libkernelapi.dylib