DllNotFoundException:
最近转Windows开发,同事c++生成的dll需要引用到opencv的dll,
先用
dependency walker 找到依赖的库,然后把所有dll直接扔到Plugins会报DllNotFoundException,初步怀疑是加载dll的顺序不同导致的。有几种解决方案:
根据上面网站的解决方法,在Editor时把依赖的dll放到安装目录Unity\Editor文件夹下,在Build后放到与.exe同目录下。
直接手动添加全局变量
public class MyPluginClass
{
static MyPluginClass()
{
String currentPath = Environment.GetEnvironmentVariable("PATH", EnvironmentVariableTarget.Process);
String dllPath = Environment.CurrentDirectory + Path.DirectorySeparatorChar + "Assets" + Path.DirectorySeparatorChar + "Plugins";
if(currentPath.Contains(dllPath) == false)
{
Environment.SetEnvironmentVariable("PATH", currentPath + Path.PathSeparator + dllPath, EnvironmentVariableTarget.Process);
}
}
}