When I copy the DLLs into the same folder where the .exe resides, it works. There is a (sort of) workaround for this, though: when I open the debugger options and add the original path of the DLL's to the environment block, it works when I start my project INSIDE my IDE, but it doesn't work when I start the project.exe file in explorer. This is not really an issue, I would just like to know the relationship between these files.
-
4DLLs need to reside either in the executable's folder, or in any other folder listed in the **PATH** environment variable on the user's system. – LaKraven Oct 21 '12 at 19:07
-
2windows had a dll search path, just like it has a PATH for finding executables. if your dll isn't somewhere in that path, it won't be found. by default the current directory (`.`) will be part of that path, and it's current directory relative to the executable's location, not whever you started running it from. – Marc B Oct 21 '12 at 19:07
-
@MarcB so, if I open the environment variables options in windows and append the original path of the DLLs, it will work when I run my exe files? – programstinator Oct 21 '12 at 19:15
-
1yah. as long as you don't have another copy/version of the relevant dlls elsewhere in the path. see: http://stackoverflow.com/questions/3623490/what-is-dll-hijacking – Marc B Oct 21 '12 at 19:16
-
Thanks. If you want to submit your comments as an answer, go ahead. I don't really know what to do when comments answer my question :) – programstinator Oct 21 '12 at 19:19
-
Short answer: to avoid dll hell... – Arnaud Bouchez Oct 22 '12 at 04:34
1 Answers
When a DLL is linked by its name only, the DLL search path is used to locate it. This search path is a complicated beast that varies depending on a variety of settings. It is documented in some detail on MSDN.
In all variants of the DLL search path, the directory from which the executable was loaded is the first directory searched. This is by far the safest way to load a DLL. Requiring modifications to the global PATH
environment variable is invasive. Requiring DLLs to be installed in system directories is invasive and against all recommendations of best practice. Requiring the use of current directory is fragile and brittle and opens security vulnerabilities.
In an ideal world, applications should be isolated. And the most effective way to achieve that is to place dependencies in the same directory as the executable files.

- 601,492
- 42
- 1,072
- 1,490