Thanks to the commenters (especially Ted Lyngmo, Ali Nazzal, and jabaa) for their diagnostic help. Their suggestions helped me isolate the problem and find the final solution.
The core issue was that the MinGW compiler's directory (C:\msys64\mingw64\bin
) was not added to the Windows PATH
environment variable.
This created a confusing situation with the following symptoms:
The g++
command worked perfectly in the VS Code integrated terminal (which likely adds the compiler to its own PATH for the session).
The command failed with missing DLL errors when run in a standalone Windows Command Prompt (which uses the system's global PATH).
The command failed silently with exit code 1
when run by the VS Code task runner, as the task runner was also using the system's global PATH and couldn't find the necessary DLLs for g++.exe
.
The problem was solved permanently by adding the MinGW bin directory to the Windows system PATH
variable:
Searched for and opened "Edit the system environment variables" in the Windows Start Menu.
Clicked on the "Environment Variables..." button.
Under "System variables", selected the Path
variable and clicked "Edit...".
Clicked "New" and added the following path:
C:\msys64\mingw64\bin
Clicked "OK" on all windows to save the changes and rebooted the computer.
After rebooting, the VS Code build task now works correctly.