Search code examples
c++dllpropertiesvisual-studio-2017dependencies

DLL's dependency cannot be found when DLL moved to another location


I'm on Windows 10, Visual Studio 2017, x64 build . . .

I have a DLL that I'm using in an exe project. We'll call it, myLibrary.dll. It comes with a .lib companion file as well. The myLibrary.dll has some other DLL dependencies that it is using. We'll call that one theDependency.dll.

I've linked the companion myLibrary.lib file in my project through Linker --> General --> Additional Library Dependencies properties. Added myLibrary.lib to the Additional Dependencies.

When I build my project, I use post build event to copy the myLibrary.dll to the Release/Debug directory of my project.

This works fine.

My issue is when I try to use myLibrary.dll in a different exe project. I get an error that it cannot find the theDependency.dll. I've used all the same property setup as the first exe project. As a test, I moved the build directory of the first exe project to another location (on the same computer) and I get the same error. "Cannot find theDependency.dll"

How is myLibrary.dll targeting it's dependencies? Not sure why the 2nd project gets this error? Also, not sure why moving the files gets this error?

Any ideas? Thanks.


Solution

  • Adding the path of the dll to the PATH environment variable worked for me.