I'm trying to load some native linux libraries using mono. I've run 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 lots of lookup positions but at least one of them SHOULD match. This is how 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, the libavformat.57
is there.
So is mono telling me that it could not be found?
The following code demonstrates what is done:
Declaration of 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 contains also a file with the name "{name of the output assembly}.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 mapping works fine. Mono takes "avformat-57" and translates it to "libavformat.57". Now mono searches for a library with the name "libavformat.57" or some related names like "libavformat.57.so". Mono searches within the directory of the executing assembly.
But, it does not manage to find the file it is looking for(according to the log posted above). So why?
Thanks!
Regards
.so
extension, it is not picking up the library correctly, try renaming it and recreate the reference to the shared library? – HamartiaMono: 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'.
do this, from the~/Desktop/cscore/cscore/Samples/LinuxSample/bin/Debug
directory,ln -s ./libavcodec.57 ./libavcodec.57.so
we're creating a symbolic link. If that fails, do this,file ./libavcodec.57
to check, It may not be in native linux compiled binary, rather, its a win32 dll? – Hamartiadlopen
to see if you can load your so successfully. – Requisite