gpt4 book ai didi

c# - System.DllNotFoundException - 如何导入 SO 文件?

转载 作者:太空狗 更新时间:2023-10-29 12:41:08 26 4
gpt4 key购买 nike

我正在使用 Monodevelop 并且有一个 C# 主程序调用一个用 C 编写的共享对象文件。解决方案构建成功,但是当我尝试运行它时,我得到上面的 System.DllNotfoundException 和一个致命的未处理异常都指向到同一个共享对象文件。

我看过以下内容:- Calling UNIX and Linux shared object file .so from c# http://mono.1490590.n4.nabble.com/Adding-libraries-to-monodevelop-td1500573.html http://www.mono-project.com/docs/advanced/pinvoke/dllnotfoundexception/ http://www.mono-project.com/docs/advanced/pinvoke/

并在此处设置 SO 文件的路径:- https://www.cyberciti.biz/faq/linux-setting-changing-library-path/

ldconfig -v 的输出显示了正确的文件夹,但没有显示 .SO 文件。其中一个链接表明 SO 文件的名称是什么无关紧要,但是如果它是相关的,我的链接不以“lib”开头。

这个应用程序以前工作过,但是由于一家公司的收购,我接管了它,我对 Monodevelop 或 linux 平台上的 C# 并不熟悉。

项目构建正常,但无法运行,因为找不到 SO 文件。

我还在 Monodevelop 的解决方案中包含了 SO 文件,并在 Build Action 选项中将其设置为 EmbeddedResource。不确定这是否必要或是否正确。

C# 代码调用:-

[DllImport("xxxxxx.so")]
protected static extern Int32 xxxxxx_init();

还有一些进一步的调用都与同一个 SO 文件有关。

一如既往地感谢任何帮助:)J

6 月 12 日更新:-因此,我查看了日志文件并发现了一大堆问题。找不到 .SO 文件,因此我已将 LDCONFIG 更新到相关目录。

这有帮助,但仅在定位 .SO 文件时 - 它仍然无法加载,因为原始 .SO 文件创建为 32 位,而我的 Monodevelop 版本是 64 位。

有什么方法可以让我在 Monodevelop 中编译 c# 代码以形成 32 位可执行文件,或者我是否必须将共享对象文件重新编译为 64 位版本? (根据我在网上找到的信息,我怀疑是后者,但我一直充满希望!)

最佳答案

免责声明:我没有使用 Mono 的经验(完全没有)。

您可能想尝试检查 .so 本身是否存在某些依赖项。

来自 here (我看到你提到了这个链接,但你没有说任何关于日志级别或检查依赖关系的事情):

Native dependencies and P/Invoke

When using native libraries via P/Invoke you may see similar errors when a library could not be located. Note that when a native library is loaded the native library may attempt to load other libraries on which it depends as well. Any failure seems to result in a DllNotFoundException which only indicates that the original native library being loaded was not found. One may thus end up with a DllNotFoundException while the library is in place.

Troubleshooting this problem can be done setting the debug log level:

$ MONO_LOG_LEVEL=debug mono YourApp.exe
<snip>
Mono-INFO: DllImport error loading library: 'Interop.so': '/usr/lib/Interop.so: undefined symbol: __some_function
<snip>

关于c# - System.DllNotFoundException - 如何导入 SO 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43896812/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com