So I will preface this question by saying that I’m pretty new to Library-Usage in C++ (just learned how to import a Dll today), so bear with me.
The project structure is as follows:
-
ComsDll (ComsDll.lib and ComsDll.dll)
-> In another project but I can edit it, this is used in the Testable project -
Testable (Testable.lib and Testable.dll and Testable.obj as outputs)
-
Google Test Project
-> Both of these are in the same solution. Testable is also generating a Dll and uses ComsDll
Now, all of these do properly build, but I can’t run the GoogleTest project because I get the following System Error:
The code execution cannot proceed because ComsDll.dll was not found. Reinstalling the problem may fix this problem.
This happens after using ComsDll.lib as an input file in the Google Tests, because otherwise I get a reference error for the functions used in Testable.h
On top of ComsDll.lib, the Google Test project also imports Testable.lib, Testable.h and Testable.obj.
The ComsDll.dll File is located in the OutputDir of both projects, alongside the ComsDll.lib file which apparently get’s found, so I’m a little confused because by my understanding the .lib references the data inside the .dll, so how can it not be found by the project if the .dll is in the same folder, mapped in the Library Include Directories?
I’m using Visual Studio 2017, all Projects compile under Release/x64 and the Code Generation is set to MDd in all 3 cases, so there should be no conflict here.
It would be really nice to get some help here, since all I could find on Google either refers to standard Libraries or cases where the solution is "move to .dll to the directory of the executable" which is here my OutputDir.
Also, if someone has a solution or idea, it would be really nice to also get an explanation as to why your solution works / mine doesn’t, so I can learn from it 🙂
PS: I would, if possible, rather not edit my local PATH variable either, since the DLL should be exportable to other machines and I don’t want to mess with enviromental variables there unless absolutely necessary
2
Answers
To quote @Richard Critten who wrote the answer as a comment: "With some exceptions Dynamic Libraries (DLLs) need to be in the same folder as the program (module) using them. For full details see here Dynamic-link library search order. You can use the project post-build step in MSVS to copy them to the right folder(s)."
Note that while most of the results will tell you to move the dll to the executable dir (OutputDir), in my case this did not work while it most certainly is also and option worth trying.
This problem can be solved by modifying the file path, I suggest you refer to the method in this issue.