本文介绍了在Mac上的Mono:尽管DLLmap中有SQLite.Interop.dll,但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:

<configuration> <dllmap dll="sqlite" target="libsqlite.0.dylib" os="osx"/> <dllmap dll="sqlite3" target="libsqlite3.0.dylib" os="osx"/></configuration>

<configuration> <dllmap dll="sqlite" target="libsqlite.0.dylib" os="osx"/> <dllmap dll="sqlite3" target="libsqlite3.0.dylib" os="osx"/></configuration>

我也尝试添加<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设置为调试并将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
  • 包含基于CIL的exe,dll和本机dylib的目录中的
  • cd
  • MONO_LOG_LEVEL =调试MONO_LOG_MASK = dll mono yourprogram.exe
  • Move those dll map files out of the way to remove them from the equation.
  • Unset DYLD_LIBRARY_PATH
  • cd in the directory that contains your CIL based exe, dlls and native dylib(s)
  • 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

这篇关于在Mac上的Mono:尽管DLLmap中有SQLite.Interop.dll,但DllNotFoundException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 15:58