DllNotFound when the plugin c++ dll links another c++ dll

I want to call c++ function in C# script. So I put the c++ dll in Assert/Plugins. However, if this dll (call it MainDll) dynamically links to another dll (call it SecondaryDll, which is also put into the Plugins folder), I will always get a DllNotFoundException.

I even write a VS C# project and calls MainDll linked with SecondaryDll in the same way as above, and everything is fine. Only not work in Unity C# script…

EDITED: No, just the MainDll as posted:

[DllImport(“MainDll”)] public static extern void FunctionMain1();

And in .cpp file which defines FunctionMain1, FunctionSec1 will be referenced, which I think is a purely c++ dynamic link:

// MainDll.cpp

include “SecondaryDll.h”
extern “C” { DLL_EXPORT void FunctionMain1() { FunctionSec1(); } }

Also, SecondaryDll may exports C++ class since it is intended to be referenced only by another c++ project rather than unity c# script, like:

// MainDll.cpp

include “SecondaryDll.h”
CSecondaryDll gObj;

extern “C” { DLL_EXPORT void FunctionMain1() { gObj.fun(); } }

I never worked with more than one DLL in Unity, but I suspect that the problem is the SecondaryDll library location: since you’ve not declared it, Unity doesn’t store this library wherever it’s storing MainDll, and MainDll can’t find it. You could try to declare any of the SecondaryDll functions in the same script you’re declaring MainDll - I suppose Unity will store both in the same folder, allowing MainDll to find SecondaryDll. Another possibility would be to place SecondaryDll in the folder System32, the default DLL location - but this would complicate things when installing your game in another machine.

A temporary solution could be to pre-merge your dll’s using library tools and to put the merged dll into Unity. This way you only have one library and problem is gone… but yeah, it’s quite an awful solution !