Skip to content

Instantly share code, notes, and snippets.

@jaymzee
Last active July 23, 2022 14:38
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jaymzee/0ca19153e2dcffa4a04cb7861b6d244f to your computer and use it in GitHub Desktop.
Save jaymzee/0ca19153e2dcffa4a04cb7861b6d244f to your computer and use it in GitHub Desktop.
visual studio code: debugging c/c++ (cl.exe)
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "cl.exe - Build and debug active file",
"type": "cppvsdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"console": "externalTerminal",
"preLaunchTask": "C/C++: cl.exe build active file",
}
]
}
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "C/C++: cl.exe build active file",
"command": "cl.exe",
"args": [
"/Zi",
"/Fe:",
"${fileDirname}\\${fileBasenameNoExtension}.exe",
"${file}"
],
"problemMatcher": ["$msCompile"],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}

Visual Studio Code: Debugging C/C++ (MSVC cl.exe)

Modify launch.json and tasks.json of your project's .vscode directory so you can debug your code within the editor.

Launch a shell with the build environment you want (for example):

  • Developer Command Prompt for VS 2019
  • x86 Native Tools Command Prompt for VS 2019
  • x64 Native Tools Command Prompt for VS 2019

Change the current directory to your project and run visual studio code from there

$ code .

Visual Studio Code will execute the build task in it's own shell inheriting from the environment of the shell it was launched from.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment