- Home /
Cant run 64-bit dlls (native plugin)
Hi all! I have a dll created for 64-bit CPUs but i am unable to import them in unity. I have used the native plugin example as reference but built my own plugin. To verify the functionality of the plugin i have written a C# application that is able to call the plugins external functions, but when i use them in unity i get: DllNotFoundException
I am running x64 version of the unity editor. Has anyone succesfully used dll files for 64-bit cpus?
cheers
Answer by Bunny83 · Sep 01, 2015 at 09:49 AM
Are you sure you read this page carefully?
To sum up the most important points:
make sure your plugin exports it's method in an
extern "C" { }
blockPlace your DLL file inside
"/Assets/Plugins/"
If you build a x86_64 plugin make sure you have selected 64 bit build in the build settings
If you want to build both 32 and 64 bit builds you have to compile two seperate versions of your plugin and place them in the appropriate sub folder of the plugins folder (
"/x86/"
and"/x86_64/"
)Finally, just in case it's not obvious: You can't use native code plugins in webplayer or WebGL builds for security reasons.
edit
I just created a simple "plugin" like this in C++:
extern "C"
{
int __declspec(dllexport) DoSomething(int a, int b)
{
return a * b ;
}
}
And use it in Unity like this:
[DllImport("UnityTestPlugin")]
private static extern int DoSomething(int a, int b);
void Start ()
{
Debug.Log("Result : " + DoSomething(3, 5));
}
And it prints "Result :15" just fine. Of course i set the target platform in VS to "x64" and in Unity i set the target platform to Windows Standalone 64 bit.
Also check the inspector when you select your dll in Unity. Now you can select for which platform and which architecture a DLL should be used. By default a DLL is used for all platforms and all architectures. However since it's a x64 DLL it makes no sense to use it in x86 builds.
If you need more help, you have to be more specific about your case. Plugins definitely work just fine.
Thanks, read through similar questions asked here and i was missing som dlls used within the created dll file. I managed to get rid of this error but when i use the dll unity crashes...
I am using a dll file, it works fine calling the functions in a visual studio console application, but when i do the same thing in unity it crashes. Any ideas for this?
thanks @Bunny83
Answer by mynameisjun · May 16, 2018 at 02:37 AM
in my case. i had the same error message. and problem was that when i change dll file in unity editor, i just delete prev one and drag and drop new dll IN EDITOR. and i found that when i delete in editor, unity automatically regenerate the dll which was just deleted. so if you got 32dll first and have deleted it in editor, nothing was being actually changed. So just go to real file location, and delete the dll in file. hope it helps anyone
Your answer
Follow this Question
Related Questions
Loading Windows 10 DLL. "This operation is only valid in the context of an app container" 1 Answer
Why the Unity3D only can load 32-bit native plugin(.so) on android platform? 1 Answer
Linux build is putting libNative.so in wrong place 1 Answer
DllNotFound Exception on Editor but works on Standalone 0 Answers
DllNotFound when the plugin c++ dll links another c++ dll 2 Answers