i had a problem in VScode cpp build , it always failed and pop up
then i click Debug Anyway then pops up
i stressed alot and try to setup .vscode folder many times.
i tried to build the cpp file using many shells , i tried cmd and it didn't work ,pwsh also didn't work ,finally i Used the shell of the MSYS2 MINGW64 because that the one i setup it,and it works✨.
i tried to make the file build and run inside VScode using the MSYS2 MINGW64 shell it self instead of making it runs through pwsh,and i manage it by .vscode/settings.json:
{
"terminal.integrated.profiles.windows": {
"bash (MSYS2)": {
"path": "C:\\msys64\\usr\\bin\\bash.exe",
"args": [
"-l",
"-i"
],
"env": {
"MSYSTEM": "MINGW64"
},
"icon": "terminal-bash"
}
},
"terminal.integrated.defaultProfile.windows": "bash (MSYS2)",
"editor.formatOnSave": true
}
this made the default shell is MINGW64
THE LAST PIECE OF PUZZLE (THE REAL PROBLEM)
i find that after setting up the tasks.json & launch.json that ✨finally✨ it run inside VScode it self , i was so happy and copy and paste the .vscode folder everywhere , but something weird happened , sometimes it build and run , and somtimes it fails due to the same previous error (the two popup messages in the start), i was shocked "is the error wasn't in the build or what"
finally , i found the real hidden problem (that you should try now if you had the same pop up messages) is QUADRATIC QUOTES , yep
inside tasks.json , you probably has :
"args": [
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}.exe"
],
and this is the problem , when this path passed to the shell ; it passed without the "" , why ?
because these quotes was the json string quotes , mean that when it passed to the shell and run ; it runs without quotes , and this can cause path problem if it has space or special chars .
the solution is quadratic quotes :
"args": [
"\"${file}\"",
"-o",
"\"${fileDirname}/${fileBasenameNoExtension}.exe\""
]
by this , two quotes will be removed and still be additional quotes to passed as "----" to the shell which solve the "no such file or directory with name ext..." error
Top comments (0)