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