c# – Linux上的Mono本机P/Invoke:DllNotFound

前端之家收集整理的这篇文章主要介绍了c# – Linux上的Mono本机P/Invoke:DllNotFound前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我正在尝试使用mono加载一些本机linux库.
我用调试标志运行mono:

Mono: DllImport attempting to load: 'libavformat.57'.
Mono: DllImport error loading library '/home/filoe/Desktop/cscore/cscore/Samples/LinuxSample/bin/Debug/libavformat.57': '/home/filoe/Desktop/cscore/cscore/Samples/LinuxSample/bin/Debug/libavformat.57: cannot open shared object file: No such file or directory'.
Mono: DllImport error loading library '/home/filoe/Desktop/cscore/cscore/Samples/LinuxSample/bin/Debug/libavformat.57.so': 'libavcodec.so.57: cannot open shared object file: No such file or directory'.
Mono: DllImport error loading library '/usr/lib/libavformat.57': '/usr/lib/libavformat.57: cannot open shared object file: No such file or directory'.
Mono: DllImport error loading library '/usr/lib/libavformat.57.so': '/usr/lib/libavformat.57.so: cannot open shared object file: No such file or directory'.
Mono: DllImport error loading library 'libavformat.57': 'libavformat.57: cannot open shared object file: No such file or directory'.
Mono: DllImport error loading library 'libavformat.57.so': 'libavformat.57.so: cannot open shared object file: No such file or directory'.
Mono: DllImport error loading library 'libavformat.57': 'libavformat.57: cannot open shared object file: No such file or directory'.
Mono: DllImport unable to load library 'libavformat.57: cannot open shared object file: No such file or directory'.
Mono: DllImport attempting to load: 'libavformat.57'.

有很多查找位置,但至少其中一个应该匹配.
这是我的目录的样子:

filoe@ubuntu:~/Desktop/cscore/cscore/Samples/LinuxSample/bin/Debug$dir
Cscore.Ffmpeg.dll     Cscore.Ffmpeg.dll.mdb  Cscore.Linux.dll.config  FFmpeg     libavformat.57  libswresample.2  LinuxSample.exe.mdb
Cscore.Ffmpeg.dll.config  Cscore.Linux.dll   Cscore.Linux.dll.mdb     libavcodec.57  libavutil.55    LinuxSample.exe  log.txt
filoe@ubuntu:~/Desktop/cscore/cscore/Samples/LinuxSample/bin/Debug$

如您所见,libavformat.57就在那里.
单声道告诉我它无法找到?

以下代码演示了完成的操作:

一些DllImport方法的声明:

[DllImport("avformat-57",EntryPoint = "av_register_all",CallingConvention = CallingConvention.Cdecl,CharSet = CharSet.Ansi)]
internal static extern void av_register_all();
[DllImport("avcodec-57",EntryPoint = "avcodec_register_all",CharSet = CharSet.Ansi)]
internal static extern void avcodec_register_all();

该项目还包含一个名为“{输出程序集的名称} .config”的文件

如您所见,映射工作正常.
Mono采用“avformat-57”并将其翻译为“libavformat.57”.
现在,mono搜索名为“libavformat.57”的库或某些相关名称,如“libavformat.57.so”.
单声道在执行程序集的目录中搜索.

但是,它无法找到它正在寻找的文件(根据上面发布的日志).所以为什么?

谢谢!

问候

最佳答案
关键是使用命令

ldd libavformat.57

使用以下输出

linux-vdso.so.1 =>  (0x00007ffdf9bd6000)
libavcodec.so.57 => not found
libavutil.so.55 => not found
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f4a74652000)
libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f4a74439000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f4a7421b000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f4a73e56000)
/lib64/ld-linux-x86-64.so.2 (0x00007f4a74d73000)

所以我已将其重命名为建议的名称并再次尝试,但没有成功.
接下来尝试一下

LD_LIBRARY_PATH=./ ldd libavformat.so.57

那是成功的.我已经调整了配置文件,现在我可以启动应用程序了

LD_LIBRARY_PATH=./ mono MyApp.exe

猜你在找的Linux相关文章