2

I wanted to know how I can set the code runner extension to use the Microsoft Visual C++ compiler. By default, trying to run the code throws an error as it is set to use the g++ compiler.

starball
  • 20,030
  • 7
  • 43
  • 238
Mohammad Ali
  • 117
  • 5

1 Answers1

0

You need to change the code-runner.executorMap setting. You can either do this in your user or workspace settings.json file. I believe you'd want something like so:

"code-runner.executorMap": {
  "cpp": "cd $dir && cl $fileName /link /out:$fileNameWithoutExt.exe && $dir$fileNameWithoutExt"
}

You can adjust it and add other commandline flags as needed (Ex /W4, /EHsc)

You might need to run VS Code from a Visual Studio Developer prompt to get a working environment.

See also https://learn.microsoft.com/en-us/cpp/build/walkthrough-compiling-a-native-cpp-program-on-the-command-line

starball
  • 20,030
  • 7
  • 43
  • 238