尝试为 Unity 构建 native c++ 插件时出现 DllNotFoundException。
第一个DLL.cpp
#include "FirstDll.h"
DLLExport int add(int a, int b){
return a+b;
}
FirstDll::FirstDll(){
}
FirstDll::~FirstDll(){
}
第一DLL.h
#define DLLExport __declspec(dllexport)
extern "C"{
DLLExport int add(int a, int b);
}
class FirstDll{
public:
FirstDll();
~FirstDll();
};
然后我通过这个命令生成一个so文件
g++ -dynamiclib -flat_namespace -fms-extensions FirstDll.cpp -o libmyclass.so
然后我在 Assets/Plugins/x86_64 文件夹和我的统一 c# 代码中添加了这个 .so 文件,我正在尝试运行这段代码。
[DllImport("myclass")]
static extern int add(int a, int b);
收到此错误后,我尝试将 so 文件移动到不同的位置并进行测试。我总是收到 DllNotFoundException。
最佳答案
尝试改用以下 clang 命令
clang *.cpp -O3 -dynamiclib -arch i386 -arch x86_64 -o libmyclass.bundle
然后确保在 Unity 中选择正确的平台
或者你可以从 Unity 中查看这个简单的插件:SimplestPluginExample
关于c++ - 使用统一 native C++ 插件时出现 DllNotFoundException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60318607/