栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

netcore调用C++动态库时异常(DllNotFoundException)

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

netcore调用C++动态库时异常(DllNotFoundException)

一.netcore调用C++提供的Windows动态库.dll异常
System.DllNotFoundException: Unable to load DLL 'xx.dll' or one of its dependencies: 找不到指定的模块。 (0x8007007E)

下载依赖项检查工具denpends,将dll拖进去会显示缺少的依赖(黄色背景问号),从sytem32或者SysWOW64中找到后复制到项目文件夹即可.

注意:以C++提供的是32位dll为例,机器是64位系统时,system32中的dll是64位的,所以应该去SysWOW64中找对应dll.

 

二.netcore调用C++提供的linux动态库.so异常
System.DllNotFoundException: Unable to load shared library 'libxx.so' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: libXX.so: cannot open shared object file: No such file or directory

异常时始终提示找不到文件,实际上文件是存在的.

使用ldd libxx.so命令可看到部分依赖项not found.

调用接口前需要设置动态库路径

StreamWriter sw = new StreamWriter("aa.sh", false, Encoding.ASCII);
string dirPath = Path.Combine(Directory.GetCurrentDirectory(), "Lib/centosx64").Trim('/').Replace("/", "\/");
sw.WriteLine($"sed -i '/{dirPath}/d' /etc/ld.so.conf");//删除配置项
sw.WriteLine($"echo '{Directory.GetCurrentDirectory()}/Lib/centosx64'>>/etc/ld.so.conf");//增加配置项
sw.WriteLine("ldconfig");
sw.Close();

Process process = new Process();
process.StartInfo.FileName = "sh";
process.StartInfo.Arguments = "aa.sh";
process.Start();
process.WaitForExit();
process.Close();

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/347410.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号