Native P / Invoke with Mono on Linux: DllNotFound

I am trying to download some native linux libraries using mono. I performed mono with the debug flag:

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'. 

There are many search items, but at least one of them MUST match. This is what my directory looks like:

 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$ 

As you can see, libavformat.57 exists. Mono tell me that it can not be found?

The following code demonstrates what has been done:

Declaring some DllImport methods:

 [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", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] internal static extern void avcodec_register_all(); 

The project also contains a file called "{output assembly name..config":

 <configuration> <dllmap os="linux" dll="avcodec-57" target="libavcodec.57"/> <dllmap os="linux" dll="avformat-57" target="libavformat.57"/> </configuration> 

As you can see above, the display is working fine. Mono accepts "avformat-57" and translates it to "libavformat.57". Mono is now looking for a library named "libavformat.57" or some related names, such as "libavformat.57.so". Mono searches the executable assembly directory.

But he fails to find the file he is looking for (according to the magazine published above). So why?

Thanks!

Hi

+6
source share
1 answer

The key was to use the command

 ldd libavformat.57 

With the following output:

 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) 

So, I renamed it the suggested names and tried it again without success. Next attempt:

 LD_LIBRARY_PATH=./ ldd libavformat.so.57 

Successfully. I adjusted the configuration file and now I can start the application using

 LD_LIBRARY_PATH=./ mono MyApp.exe 
+2
source

Source: https://habr.com/ru/post/1013074/


All Articles