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();

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值