c# - 使用 Mono P/Invoke : Why? 的 DllNotFoundException

标签 c# .net mono pinvoke

尝试从 C#(使用 Mono)调用我的 native 库时,我不断收到 DllNotFoundExceptions。我有一个 native 库,我正在为其添加绑定(bind)。

这是我看到的:

$ grep DllImport generated/NativeLibrawLoader.cs | head -n 1
[DllImport("libfspotraw.dll")]



$ cat libfspotraw-sharp.dll.config
<configuration>
  <dllmap dll="libglib-2.0-0.dll" target="libglib-2.0.so.0"/>
  <dllmap dll="libgobject-2.0-0.dll" target="libgobject-2.0.so.0"/>
  <dllmap dll="libgthread-2.0-0.dll" target="libgthread-2.0.so.0"/>
  <dllmap dll="libatk-1.0-0.dll" target="libatk-1.0.so.0"/>
  <dllmap dll="libgtk-win32-2.0-0.dll" target="libgtk-x11-2.0.so.0"/>
  <dllmap dll="libgdk-win32-2.0-0.dll" target="libgdk-x11-2.0.so.0"/>
  <dllmap dll="libgdk_pixbuf-2.0-0.dll" target="libgdk_pixbuf-2.0.so.0"/>
  <dllmap dll="libfspotraw.dll" target="/opt/gnome//lib/f-spot/libfspotraw.so.0"/>
</configuration>

以及 strace 日志的摘录:

5856  1247991911.215674 open("lib/opt/gnome//lib/f-spot/libfspotraw.so.0.so", O_RDONLY) = -1 ENOENT (No such file or directory)
5856  1247991911.215814 open("lib/opt/gnome//lib/f-spot/libfspotraw.so.0.so.la", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory)
5856  1247991911.215923 open("./lib/opt/gnome//lib/f-spot/libfspotraw.so.0.so", O_RDONLY) = -1 ENOENT (No such file or directory)
5856  1247991911.215992 open("./lib/opt/gnome//lib/f-spot/libfspotraw.so.0.so.la", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory)
5856  1247991911.216083 open("/opt/gnome//lib/f-spot/libfspotraw.so.0", O_RDONLY) = 25
5856  1247991911.216154 read(25, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0000\277\0\0004\0\0\0\\"..., 512) = 512
5856  1247991911.216226 fstat64(25, {st_mode=S_IFREG|0755, st_size=923041, ...}) = 0
5856  1247991911.216320 mmap2(NULL, 806536, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 25, 0) = 0x2a26000
5856  1247991911.216431 mmap2(0x2a99000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 25, 0x72) = 0x2a99000
5856  1247991911.216506 mmap2(0x2a9f000, 310920, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x2a9f000
5856  1247991911.216563 close(25)       = 0
5856  1247991911.217258 munmap(0x2a26000, 806536) = 0
5856  1247991911.217333 open("/opt/gnome//lib/f-spot/libfspotraw.so.0.la", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory)
5856  1247991911.217476 open("lib/opt/gnome//lib/f-spot/libfspotraw.so.0.so", O_RDONLY) = -1 ENOENT (No such file or directory)
5856  1247991911.217548 open("lib/opt/gnome//lib/f-spot/libfspotraw.so.0.so.la", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory)
5856  1247991911.217640 open("./lib/opt/gnome//lib/f-spot/libfspotraw.so.0.so", O_RDONLY) = -1 ENOENT (No such file or directory)
5856  1247991911.217708 open("./lib/opt/gnome//lib/f-spot/libfspotraw.so.0.so.la", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory)
5856  1247991911.217798 open("lib/opt/gnome//lib/f-spot/libfspotraw.so.0", O_RDONLY) = -1 ENOENT (No such file or directory)
5856  1247991911.217866 open("lib/opt/gnome//lib/f-spot/libfspotraw.so.0.la", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory)
5856  1247991911.218135 open("lib/opt/gnome//lib/f-spot/libfspotraw.so.0.so", O_RDONLY) = -1 ENOENT (No such file or directory)
5856  1247991911.218215 open("lib/opt/gnome//lib/f-spot/libfspotraw.so.0.so.la", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory)
5856  1247991911.218307 open("./lib/opt/gnome//lib/f-spot/libfspotraw.so.0.so", O_RDONLY) = -1 ENOENT (No such file or directory)
5856  1247991911.218398 open("./lib/opt/gnome//lib/f-spot/libfspotraw.so.0.so.la", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory)
5856  1247991911.218490 open("/opt/gnome//lib/f-spot/libfspotraw.so.0", O_RDONLY) = 25
5856  1247991911.218556 read(25, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0000\277\0\0004\0\0\0\\"..., 512) = 512
5856  1247991911.218653 fstat64(25, {st_mode=S_IFREG|0755, st_size=923041, ...}) = 0
5856  1247991911.218741 mmap2(NULL, 806536, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 25, 0) = 0x2a26000
5856  1247991911.218809 mmap2(0x2a99000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 25, 0x72) = 0x2a99000
5856  1247991911.218872 mmap2(0x2a9f000, 310920, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x2a9f000
5856  1247991911.218924 close(25)       = 0
5856  1247991911.219514 munmap(0x2a26000, 806536) = 0
5856  1247991911.219583 open("/opt/gnome//lib/f-spot/libfspotraw.so.0.la", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory)
5856  1247991911.219697 open("lib/opt/gnome//lib/f-spot/libfspotraw.so.0.so", O_RDONLY) = -1 ENOENT (No such file or directory)
5856  1247991911.219769 open("lib/opt/gnome//lib/f-spot/libfspotraw.so.0.so.la", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory)
5856  1247991911.219859 open("./lib/opt/gnome//lib/f-spot/libfspotraw.so.0.so", O_RDONLY) = -1 ENOENT (No such file or directory)
5856  1247991911.219927 open("./lib/opt/gnome//lib/f-spot/libfspotraw.so.0.so.la", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory)
5856  1247991911.220584 open("lib/opt/gnome//lib/f-spot/libfspotraw.so.0", O_RDONLY) = -1 ENOENT (No such file or directory)
5856  1247991911.220666 open("lib/opt/gnome//lib/f-spot/libfspotraw.so.0.la", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory)
5856  1247991911.224316 write(1, "\33[93m"..., 5) = 5
5856  1247991911.224531 gettimeofday({1247991911, 224545}, NULL) = 0
5856  1247991911.224583 gettimeofday({1247991911, 224595}, NULL) = 0
5856  1247991911.224625 gettimeofday({1247991911, 224637}, NULL) = 0
5856  1247991911.224667 gettimeofday({1247991911, 224679}, NULL) = 0
5856  1247991911.224737 write(1, "[Warn  10:25:11.224]"..., 20) = 20
5856  1247991911.224825 write(1, "\33[0m"..., 4) = 4
5856  1247991911.224949 write(1, " Caught an exception - /opt/gnome"..., 1024) = 1024
5856  1247991911.225511 write(1, "amming/Gnome/f-spot/src/PhotoImag"..., 248) = 248
5856  1247991911.225674 write(1, "\n"..., 1) = 1

它看起来好像找到了库,但随后忽略了这一事实并继续探测各种不存在的文件。有谁知道为什么吗?

最佳答案

您始终可以使用此技巧调试这些问题(如手册页中所述):

MONO_LOG_LEVEL="debug"MONO_LOG_MASK="dll"mono glue.exe

关于c# - 使用 Mono P/Invoke : Why? 的 DllNotFoundException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1149493/

相关文章:

c# - 从 System.Web.UI.UserControl 基类继承

c# - 获取列表框选定的项目

c# - 使用 Blazor 渲染未知深度的树结构

.net - 从 .NET 安全地释放 COM 对象引用

c# - 如何获取基类型字段的值

c# - 使用 mono-devel 在 Linux 上运行 C# 二进制文件

c# - Monomac System.Net.WebRequest 的类型初始值设定项所显示的异常

c# - Entity Framework 数据库小数点后一位精度

c# - 是否有 "String.Format"可以接受命名输入参数而不是索引占位符?

c# - 是否可以使用 Mono AOT 编译( native )c# 可执行文件和具有未实现 Mono 方法的 C# Dll(CIL)