Vscode-code-runner: Configure coderunner for C++ Build Tools(MSVC)

Created on 13 Jul 2018  ·  5Comments  ·  Source: formulahendry/vscode-code-runner

By default, code-runner is configured for mingw(g++).

_How can I configure it for C++ Build Tools(MSVC or cl.exe)._

fyi question

Most helpful comment

here is the contents of the settings.json that worked for me

`{
"files.autoSave": "afterDelay",
"code-runner.runInTerminal": true,

"code-runner.executorMap": {
    "python": "$pythonPath -u $fullFileName",
    "cpp": " \"C:/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/Common7/Tools/VsDevCmd.bat\" && cd $dir && cl $fileName /fe$fileNameWithoutExt.exe && $dir$fileNameWithoutExt.exe ",
}

}`

All 5 comments

"cpp": "\"MyFolder\VC\bin\amd64\vcvars64.bat\" && cd $dir && cl $fileName /fe$fileNameWithoutExt.exe && $dir$fileNameWithoutExt.exe ",

Thanks

here is the contents of the settings.json that worked for me

`{
"files.autoSave": "afterDelay",
"code-runner.runInTerminal": true,

"code-runner.executorMap": {
    "python": "$pythonPath -u $fullFileName",
    "cpp": " \"C:/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/Common7/Tools/VsDevCmd.bat\" && cd $dir && cl $fileName /fe$fileNameWithoutExt.exe && $dir$fileNameWithoutExt.exe ",
}

}`

below is my setup with "/Zi /EHsc /Fe:" args that I saw from the official document of VSCode on VC++ setup. The filepath of VsDevCmd.bat might vary depending on your version of VS.
"code-runner.executorMap": { "cpp": " \"C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/Common7/Tools/VsDevCmd.bat\" && cd $dir && cl $fileName /Zi /EHsc /Fe:$fileNameWithoutExt.exe && $dir$fileNameWithoutExt.exe ", }

This is one work for me when Default Shell is set to PowerShell. It doesn't work for Command prompt (cmd.exe) (File VsDevCmd.bat is for cmd.exe). I've set it for C language ("c") but probably should work for C++ ("cpp"):

"code-runner.executorMap": {
"c": "Import-Module \"C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/Common7/Tools/Microsoft.VisualStudio.DevShell.dll\"; Enter-VsDevShell 00595aab; cd $dir; cl $fileName && del $fileNameWithoutExt.obj && Clear-Host && Start-Process pwsh -ArgumentList \"-Command  &{.\\$fileNameWithoutExt; pause}\"",

Command Line for PowerShell:
Import-Module \"C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/Common7/Tools/Microsoft.VisualStudio.DevShell.dll\"; Enter-VsDevShell 00595aab
was extracted from the Developer PowerShell for VS 2019 Windows Start Menu shortcut within its Properties -> Target. Keep in mind that every Enter-VsDevShell has his own unique ID number. You must use your own one.

Command Line for cmd.exe:
\"C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/Common7/Tools/VsDevCmd.bat\"
was extracted from the Developer Command Prompt for VS 2019 Windows Start Menu shortcut (within: Properties -> Target)

Was this page helpful?
0 / 5 - 0 ratings