Problem
You’ve made an application that works fine in your development environment, but fails to start in clear environment. You seemed to copy all the needed DLLs, but the error dialog like below keeps showing up.
Prerequisites
-
Some application fails to start due to DLL loading errors.
-
You know where to get the missing DLL(s) from. For example, MSYS2/MinGW64/Cygwin/GTK DLLs, see Example
-
You have Debugging Tools for Windows already installed.
Debugging algorithm
-
Run Command Prompt (cmd.exe)
-
Go to directory where APP.exe is located
> cd PATH_TO_APP
-
Add gflags, WinDbg, CDB to PATH
> set PATH=C:\Program Files (x86)\Windows Kits\10\Debuggers\x64\;%PATH%
-
Enable loader snaps for APP.exe
> gflags /i APP.exe +sls
-
Run APP.exe under WinDbg or CDB
I found that using CDB to find and copy the missing DLL(s) is much more convenient than using WinDbg, since you don’t leave the terminal. The commands “g;q” mean start debugging (go) and quit (q) on error.
> cdb -c "g;q" APP.exe
-
Look for the DLL loading errors like
... ERROR: Unable to load DLL: "some-name.dll",
-
Copy some-name.dll to the current directory
> copy PATH_TO_DLL\some-name.dll .
-
Continue the steps 5 to 7 until there’s no more DLL loading errors
-
Disable loader snaps for APP.exe
> gflags /i APP.exe -sls
-
You’re done
Example
> cdb -c "g;q" node src\main.js 2>nul | findstr /R /c:"Unable to load DLL: .*\.dll"
... LdrpProcessWork - ERROR: Unable to load DLL: "libglib-2.0-0.dll", ...
... LdrpProcessWork - ERROR: Unable to load DLL: "libgmodule-2.0-0.dll", ...
> copy \msys64\mingw64\bin\libglib-2.0-0.dll .
1 file(s) copied.
> copy \msys64\mingw64\bin\libgmodule-2.0-0.dll .
1 file(s) copied.
Continue the above commands sequence until there’s no more DLL loading errors.
See real-world example here.
Post Scriptum
For simple cases Process Monitor or even Dependency Walker might be easier to use.