My C++ DLL does not know how to find the OpenCV libraries inside the same directory it is located

When I call to the DLL called test.dll that is inside a folder called libs this one does not work, instead when I place the OpenCV DLL inside the folder of the program it works, is there some way to make that it prefers the own PATH of the DLL test.dll instead of the folder from where I call it without modifying the environment variables?

please be more precise, details are important.

please, have another look at your post, and realize – we’ve no idea, what you’re actually doing :[

make a duplicate of needed dll to work around the issue

I have created my DLL that executes some OpenCV functions, but when I place my DLL next to the OpenCV DLLs it does not work, because for some reason it prefers the execution place of the main program rather than its own path to look for the libraries, I compile my own version of OpenCV 4.7.0 in Visual Studio 22 with CMake and then my own DLL using Clang. Is there any way that my compiled DLL instead of preferring the execution path chooses its own PATH to look for the libraries.

For example, to make it work I had to place a temporary environment variable in my program before calling my DLL, but it seems to me a very ‘aggressive’ solution. Otherwise I would have to place the OpenCV DLLs in the root of my program.

I find it strange that it works with an environment variable, but when I place my DLL along with the libraries in a folder other than the root of the program from where I call the DLL it doesn’t work.

Thank you in advance for your patience and kindness.