Mac 上的 Mono:尽管 SQLite.Interop.dll 在 dllmap 中,但仍出现 DllNotFoundException

我有一个使用 SQLite 并且在 Windows 上运行良好的 C# 应用程序.

I have a C# application that uses SQLite and works fine on Windows.

相同的 Visual Studio 项目在 Xamarin Studio 中编译良好,但运行时我得到:

The same Visual Studio project compiles fine in Xamarin Studio, but when running I get:

DllNotFoundException: SQLite.Interop.dll

尽管:

  • libsqlite3.0.dylib 位于 /usr/lib 中,并且与可执行文件和其他 DLL 位于同一文件夹中
  • .$DYLD_LIBRARY_PATH
  • 的一部分
  • 可执行文件和所有使用 SQLite 的 DLL 都有一个匹配的 <the_exe_or_dll_including_filename_extension>.config 文件,其中包含:
  • libsqlite3.0.dylib is in /usr/lib and also in the same folder as the executable and other DLLs
  • . is part of the $DYLD_LIBRARY_PATH
  • The executable and all SQLite-using DLLs have a matching <the_exe_or_dll_including_filename_extension>.config file containing:

<代码><配置><dllmap dll="sqlite" target="libsqlite.0.dylib" os="osx"/><dllmap dll="sqlite3" target="libsqlite3.0.dylib" os="osx"/></配置>

我也试过添加 <dllmap dll="SQLite.Interop.dll" target="libsqlite3.0.dylib" os="osx"/>,不是更好.

I also tried adding <dllmap dll="SQLite.Interop.dll" target="libsqlite3.0.dylib" os="osx"/>, not better.

有什么问题?

推荐答案

通过将 MONO_LOG_LEVEL 设置为 debug 并将 MONO_LOG_MASK 过滤设置为仅与 DLL 相关的消息,您可以轻松找到 mono 在哪里寻找该本地库.

You can easily find where mono is looking for that native library by setting the MONO_LOG_LEVEL to debug and MONO_LOG_MASK filtering to only DLL related messages.

export MONO_LOG_LEVEL=debug
export MONO_LOG_MASK=dll
mono yourprogram.exe

或作为一个衬里,因此您不必取消设置环境变量:

or as a one liner so you do not have to unset env vars:

MONO_LOG_LEVEL=debug MONO_LOG_MASK=dll mono yourprogram.exe

Mono 和 OS-X 动态链接编辑器('man dyld' 了解详细信息)不需要将 DYLD_LIBRARY_PATH 设置为当前目录 ('.').注意:Linux 确实需要 LD_LIBRARY_PATH 来包含当前目录,如果这是您的意图的话.

Mono and the OS-X dynamic link editor ('man dyld' for details) does not require DYLD_LIBRARY_PATH to be set to the current directory ('.'). Note: Linux does require LD_LIBRARY_PATH to include the current directory, if that is your intention.

  • 将这些 dll 映射文件移开,以将它们从方程式中移除.
  • 取消设置 DYLD_LIBRARY_PATH
  • cd 在包含基于 CIL 的 exe、dll 和本机 dylib 的目录中
  • MONO_LOG_LEVEL=debug MONO_LOG_MASK=dll mono yourprogram.exe

使用本机 dll/共享库跟踪输出,您可以跟踪未找到哪个库(或其依赖项之一),或者它是否是您的单声道版本的错误 ARCH.

Using the native dll/shared library trace output you can track which library is not being found (or one of its dependancies) or if it is the wrong ARCH for your mono version.

如果您仍然遇到问题,我们需要知道您正在使用哪个 SQLite 库来编译它(或者如果通过 Nuget 获得它,则为 Arch 版本).发布您的 dll 跟踪输出也会很快解决问题.

If you are still having problems, we would need to know which SQLite library you are using the options that you are using to compile it (or the arch version if getting it via a Nuget). A posting your dll trace output would quickly solve things also.

注意事项:

我假设您正在使用 System.Data.SQLite 库并正在编译选项/p:UseInteropDll=true/p:UseSqliteStandard=false".

I am assuming you are using the System.Data.SQLite library and are compiling the the options "/p:UseInteropDll=true /p:UseSqliteStandard=false".

Mono 在其默认安装中包含一个 SQLite,它在 OS-X 上为 32 位:

Mono includes a SQLite in it's default install, it is 32-bit on OS-X:

file /Library/Frameworks/Mono.framework/Versions/4.0.2/lib/libsqlite3.dylib
/Library/Frameworks/Mono.framework/Versions/4.0.2/lib/libsqlite3.dylib: Mach-O dynamically linked shared library i386

假设您使用的是 Mono 的 OS-X 软件包安装程序,因此获得的是 32 位版本的 Mono,因此需要 32 位版本的本机库.

Assuming you are using the OS-X package installer from Mono, thus are getting the 32-bit version of Mono and thus need 32-bit versions of the native libraries.

>>file `which mono`
/usr/bin/mono: Mach-O executable i386

/usr/lib/libsqlite3.0.dylib 是一个多 ARCH 胖二进制文件,因此该库不是问题,但您的调试输出可能会显示另一个问题,

The /usr/lib/libsqlite3.0.dylib is a multi ARCH fat binary, so that library is not a problem, but your debug output might show another one that is a problem,

>>file /usr/lib/libsqlite3.0.dylib
libsqlite3.0.dylib: Mach-O universal binary with 3 architectures
libsqlite3.0.dylib (for architecture x86_64):   Mach-O 64-bit dynamically linked shared library x86_64
libsqlite3.0.dylib (for architecture i386): Mach-O dynamically linked shared library i386
libsqlite3.0.dylib (for architecture x86_64h):  Mach-O 64-bit dynamically linked shared library x86_64

相关文章