- Home /
What is the correct location for a native (C++) plugin's DLL dependencies
I have built a native Unity plugin (for deployment on Windows) in C++. This plugin (a DLL) itself depends on a number of other DLLs. So for example let's call my plugin MyPlugin.dll, and assume it depends on another DLL called Dep.dll.
I understand that MyPlugin.dll should go into the Assets/Plugins/x86 folder (it's a 32 bit plugin in my case). The question is what is the right location for Dep.dll. Assume that Dep.dll is not in my system path.
As far as I can tell there are two options:
Place Dep.dll in the root folder of the project
Place Dep.dll alongside my plugin in Assets/Plugins/x86
For running in the Unity Editor, both options work. However, interestingly when trying option (1) Unity prints the following error to debug console (but besides the appearance of the error, it actually still works!)
Failed to load 'Assets/Plugins/x86/MyPlugin.dll' with error 'The specified module could not be found. ', GetDllDirectory returned ''. If GetDllDirectory returned non empty path, check that you're using SetDirectoryDll correctly.
Things get more complicated when building & deploying the standalone Windows application. If I use option (2) above then the DLLs get deployed to APP_Data/Plugins (assuming APP is the deployed application name). And the app doesn't work because Dep.dll presumably is not found at runtime. (The way I can make this work is to create a batch file which first appends APP_Data/Plugins to the system path, prior to running the app).
Alternatively if Dep.dll is kept alongside the app's EXE then it does work, though aesthetically it would be nicer if I could hide Dep.dll in the plugins folder with the rest of the DLLs
So I guess my question is whether there is some way (using SetDllDirectory?) to allow me to keep Dep.dll with all other DLLs under the plugins folder, and still have it found at runtime, without having to add it to system path using a wrapper batch file or anything?
Thanks
Answer by umair_hassan · Jun 06, 2016 at 11:02 AM
Hi, If it helps, this is what I did to get mine working (Windows 7, Unity 5.3.4f1, Google VR SDK for Unity v0.8): 1. Close Unity Completely 2. Using the file browser, navigate to your projects: Assets\Plugins\ 3. Delete the x86_64 folder (The only thing in this folder was the previous audioplugingvrunity.dll) 4. If you have x86_64.meta file, delete that too. 5. Open up your unity project and re-import the package.
At that point, it imported properly and was detected properly as well.
Your answer
Follow this Question
Related Questions
How to step into a native C++ dll in Visual Studio? 0 Answers
Native Plugin Cleanup 0 Answers
Texture2D manipulation in c++ dll Plugin 0 Answers
Native Plugin works in editor but not in build 0 Answers
DllNotFound Exception on Editor but works on Standalone 0 Answers