Reputation: 11
Getting DllNotFoundException when trying to build a native c++ plugin for Unity.
FirstDll.cpp
#include "FirstDll.h"
DLLExport int add(int a, int b){
return a+b;
}
FirstDll::FirstDll(){
}
FirstDll::~FirstDll(){
}
FirstDll.h
#define DLLExport __declspec(dllexport)
extern "C"{
DLLExport int add(int a, int b);
}
class FirstDll{
public:
FirstDll();
~FirstDll();
};
I am then generating a so file via this command
g++ -dynamiclib -flat_namespace -fms-extensions FirstDll.cpp -o libmyclass.so
I am then added this .so file in Assets/Plugins/x86_64 folder and in my unity c# code, I am trying to run this piece of code.
[DllImport("myclass")]
static extern int add(int a, int b);
After getting this error, I have tried to moved the so file to different locations and test. I am always getting DllNotFoundException.
Upvotes: 1
Views: 1593
Reputation: 681
Try using the following clang command instead
clang *.cpp -O3 -dynamiclib -arch i386 -arch x86_64 -o libmyclass.bundle
Then make sure to select the correct platform in Unity
Or you can check this simple plugin from Unity: SimplestPluginExample
Upvotes: 1