2016-12-11 197 views
6

我試圖使用mono加載一些本機linux庫。 我已經跑單與調試標誌:在Linux上使用Mono進行本地P /調用:DllNotFound

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

有很多查找位置,但它們中的至少一個應該匹配。 這是我的目錄看起來像:

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

該項目還包含一個名稱爲文件「{輸出程序集的名稱}的.config 「:

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

正如你在上面看到的,映射工作正常。 單聲道需要「avformat-57」並將其轉換爲「libavformat.57」。 現在單聲道搜索名爲「libavformat.57」或類似「libavformat.57.so」的相關名稱的庫。 在執行程序集的目錄中進行單聲道搜索。

但是,它無法找到它正在尋找的文件(根據上面公佈的日誌)。所以爲什麼?

謝謝!

問候

+0

共享庫有一個'.so'擴展,這是不正確拿起庫,嘗試重命名,並重新創建參考共享庫? – t0mm13b

+0

不,它不會彙集我正在使用的擴展名或文件名的組合。錯誤信息是一個肯定存在的文件,不能被mono找到。 –

+0

告訴我們一個[MCVE]來證明這一點。 – t0mm13b

回答

2

的關鍵是使用命令

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 
+0

只是好奇,爲什麼不使用Ubuntu軟件包管理器來安裝libavformat? – Matt

+0

奇怪的是,這正是我在評論中所說的;) –