CINXE.COM
Get Started with C++ and MinGW-w64 in Visual Studio Code
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="awa-expId" content="vscw_aaflight1016_treatment:103440;" /> <meta name="awa-env" content="prod" /> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="google-site-verification" content="hNs7DXrTySP_X-0P_AC0WulAXvUwgSXEmgfcO2r79dw" /> <!-- Twitter and Facebook OpenGraph Metadata--> <meta name="twitter:card" content="summary_large_image" /> <meta name="twitter:site" content="@code" /> <meta name="description" content="Configuring the C++ extension in Visual Studio Code to target g++ and gdb on a MinGW-w64 installation" /> <meta name="keywords" content="" /> <meta name="ms.prod" content="vs-code" /> <meta name="ms.TOCTitle" content="GCC on Windows" /> <meta name="ms.ContentId" content="7efec972-6556-4526-8aa8-c73b3319d612" /> <meta name="ms.date" content="12/14/2023" /> <meta name="ms.topic" content="conceptual" /> <!-- Twitter and Facebook OpenGraph Metadata--> <meta name="twitter:card" content="summary_large_image" /> <meta property="og:url" content="https://code.visualstudio.com/docs/cpp/config-mingw" /> <meta property="og:type" content="article" /> <meta property="og:title" content="Get Started with C++ and MinGW-w64 in Visual Studio Code" /> <meta property="og:description" content="Configuring the C++ extension in Visual Studio Code to target g++ and gdb on a MinGW-w64 installation" /> <meta property="og:image" content="https://code.visualstudio.com/opengraphimg/opengraph-docs.png" /> <link rel="shortcut icon" href="/favicon.ico" sizes="128x128" /> <link rel="apple-touch-icon" href="/apple-touch-icon.png"> <title>Get Started with C++ and MinGW-w64 in Visual Studio Code</title> <link rel="stylesheet" href="/vendor/bootstrap/css/bootstrap.min.css"> <link rel="stylesheet" href="/dist/v2/style.css"> <script src="https://consentdeliveryfd.azurefd.net/mscc/lib/v2/wcp-consent.js"></script> <script type="text/javascript" src="https://js.monitor.azure.com/scripts/c/ms.analytics-web-4.min.js"></script> <script type="text/javascript"> // Leave as var; siteConsent is initialized and referenced elsewhere. var siteConsent = null; const GPC_DataSharingOptIn = false; WcpConsent.onInitCallback(function () { window.appInsights = new oneDS.ApplicationInsights(); window.appInsights.initialize({ instrumentationKey: "1a3eb3104447440391ad5f2a6ee06a0a-62879566-bc58-4741-9650-302bf2af703f-7103", propertyConfiguration: { userConsented: false, gpcDataSharingOptIn: false, callback: { userConsentDetails: siteConsent ? siteConsent.getConsent : undefined }, }, cookieCfg: { ignoreCookies: ["MSCC"] }, webAnalyticsConfiguration:{ // Web Analytics Plugin configuration urlCollectQuery: true, urlCollectHash: true, autoCapture: { scroll: true, pageView: true, onLoad: true, onUnload: true, click: true, resize: true, jsError: true } } }, []); window.appInsights.getPropertyManager().getPropertiesContext().web.gpcDataSharingOptIn = GPC_DataSharingOptIn; }); </script> <link rel="alternate" type="application/atom+xml" title="RSS Feed for code.visualstudio.com" href="/feed.xml" /> </head> <body > <!-- Setting theme here to avoid FOUC --> <script> function setTheme(themeName) { if (themeName === 'dark') { document.documentElement.removeAttribute('data-theme'); // dark is default, so no data-theme attribute needed } if (themeName === 'light') { document.documentElement.setAttribute('data-theme', themeName); } return; } // Determine initial theme: user preference or system preference let theme = localStorage.getItem('theme') || (window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'); setTheme(theme); // Apply the initial theme // Listen for changes in the system theme preference window.matchMedia('(prefers-color-scheme: dark)').addListener(e => { if (!localStorage.getItem('theme')) { // Only if no user preference is saved setTheme(e.matches ? 'dark' : 'light'); } }); </script> <div id="main"> <div class="navbar-fixed-container"> <div class="navbar navbar-inverse navbar-fixed-top " data-spy="affix" data-offset-top="1"> <div id='cookie-banner'></div> <nav role="navigation" aria-label="Top Level"> <div class="container"> <div class="nav navbar-header"> <a class="navbar-brand" href="/"><span>Visual Studio Code</span></a> <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse" aria-label="Expand and Collapse Menu"> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> </div> <div class="navbar-collapse collapse"> <ul class="nav navbar-nav navbar-left"> <li class="active" ><a id="nav-docs" href="/docs">Docs</a></li> <li ><a id="nav-updates" href="/updates">Updates</a></li> <li ><a id="nav-blogs" href="/blogs">Blog</a></li> <li ><a id="nav-extend" href="/api">API</a></li> <li><a href="https://marketplace.visualstudio.com/VSCode" target="_blank" rel="noopener" id="nav-extensions">Extensions</a></li> <li ><a id="nav-faqs" href="/docs/supporting/faq">FAQ</a></li> <li class='search visible-xs visible-sm' ><a href="/Search">Search</a></li> <li ><a id="nav-copilot" href="/docs/copilot/overview">GitHub Copilot</a></li> </ul> </ul> <ul class="nav navbar-nav navbar-right" role="presentation"> <li> <button type="button" class="theme-switch" id="theme-toggle"> <img class="theme-icon-light" src="/assets/icons/theme-light.svg" alt="Switch to the dark theme" /> <img class="theme-icon-dark" src="/assets/icons/theme-dark.svg" alt="Switch to the light theme" /> </button> </li> <li> <a href="/Search" title="Search" class="btn search-btn" id="nav-search"> <img class="search-icon-light" src="/assets/icons/search.svg" width="16px" height="16px" alt="Search" /> <img class="search-icon-dark" src="/assets/icons/search-dark.svg" width="16px" height="16px" alt="Search" /> </a> </li> <li class="search" role="presentation"> <form class="nav-search search-form" role="search" aria-label="Search"> <div class="input-group" role="presentation"> <input type="text" name="q" class="search-box form-control" placeholder="Search Docs" aria-label="Search text"/> <span class="input-group-btn"> <button tabindex="0" class="btn" type="submit" aria-label="Search"> <img class="search-icon-dark" src="/assets/icons/search-dark.svg" alt="Search" /> <img class="search-icon-light" src="/assets/icons/search.svg" alt="Search" /> </button> </span> </div> </form> </li> <!-- this was hiden in the home and download page, keeping it for now --> <li><a class="link-button" href="/Download" id="nav-download"> <span>Download</span></a></li> </ul> </div> </div> </nav> </div> </div> <div class="updates-banner "> <div class="container"> <p class="message"><a href="/updates" id="banner-link-updates">Version 1.95</a> is now available! Read about the new features and fixes from October.</p> </div> <div tabindex="0" role="button" title="Dismiss this update" class="dismiss-btn" id="banner-dismiss-btn"><span class="sr-only">Dismiss this update</span><span aria-hidden="true" class="glyph-icon"></span></div> </div> <!-- This div wraps around the entire site --> <!-- The body itself should already have a main tag --> <div id="main-content"> <script> function closeReportIssue() { var element = document.getElementById('surveypopup'); element.parentElement.removeChild(element); } function reportIssue(tutorial, page) { var div = document.createElement('div'); div.innerHTML = '<div id="surveypopup" class="overlay visible"><div class="surveypopup"><div id="surveytitle">Tell us more<a href="javascript:void(0)" onclick="closeReportIssue()">X</a></div><div id="surveydiv"><iframe frameBorder="0" scrolling="0" src="https://www.research.net/r/PWZWZ52?tutorial=' + tutorial + '&step=' + page + '"></iframe></div></div></div>'; document.body.appendChild(div.children[0]); } </script> <div class="container body-content docs"> <div class="row"> <!-- left nav --> <div class="col-xs-12 col-md-2 docs-navbar-container"> <nav id="docs-navbar" aria-label="Topics" class="docs-nav visible-md visible-lg"> <ul class="nav" id="main-nav"> <li > <a class="docs-home" href="/docs" >Overview</a> </li> <li class="panel collapsed"> <a class="area" role="button" href="#setup-articles" data-parent="#main-nav" data-toggle="collapse">Setup</a> <ul id="setup-articles" class="collapse "> <li > <a href="/docs/setup/setup-overview" >Overview</a> </li> <li > <a href="/docs/setup/linux" >Linux</a> </li> <li > <a href="/docs/setup/mac" >macOS</a> </li> <li > <a href="/docs/setup/windows" >Windows</a> </li> <li > <a href="/docs/setup/raspberry-pi" >Raspberry Pi</a> </li> <li > <a href="/docs/setup/network" >Network</a> </li> <li > <a href="/docs/setup/additional-components" >Additional Components</a> </li> <li > <a href="/docs/setup/enterprise" >Enterprise</a> </li> <li > <a href="/docs/setup/uninstall" >Uninstall</a> </li> </ul> </li> <li class="panel collapsed"> <a class="area" role="button" href="#getstarted-articles" data-parent="#main-nav" data-toggle="collapse">Get Started</a> <ul id="getstarted-articles" class="collapse "> <li > <a href="/docs/getstarted/getting-started" >Tutorial</a> </li> <li > <a href="/docs/getstarted/introvideos" >Intro Videos</a> </li> <li > <a href="/docs/getstarted/tips-and-tricks" >Tips and Tricks</a> </li> <li > <a href="/docs/getstarted/userinterface" >User Interface</a> </li> <li > <a href="/docs/getstarted/themes" >Themes</a> </li> <li > <a href="/docs/getstarted/settings" >Settings</a> </li> <li > <a href="/docs/getstarted/keybindings" >Key Bindings</a> </li> <li > <a href="/docs/getstarted/locales" >Display Language</a> </li> <li > <a href="/docs/getstarted/telemetry" >Telemetry</a> </li> <li > <a href="/docs/getstarted/educators-and-students" >Educators & Students</a> </li> </ul> </li> <li class="panel collapsed"> <a class="area" role="button" href="#editor-articles" data-parent="#main-nav" data-toggle="collapse">User Guide</a> <ul id="editor-articles" class="collapse "> <li > <a href="/docs/editor/codebasics" >Basic Editing</a> </li> <li > <a href="/docs/editor/extension-marketplace" >Extension Marketplace</a> </li> <li > <a href="/docs/editor/intellisense" >IntelliSense</a> </li> <li > <a href="/docs/editor/editingevolved" >Code Navigation</a> </li> <li > <a href="/docs/editor/refactoring" >Refactoring</a> </li> <li > <a href="/docs/editor/debugging" >Debugging</a> </li> <li > <a href="/docs/editor/testing" >Testing</a> </li> <li > <a href="/docs/editor/vscode-web" >VS Code for the Web</a> </li> <li > <a href="/docs/editor/tasks" >Tasks</a> </li> <li > <a href="/docs/editor/profiles" >Profiles</a> </li> <li > <a href="/docs/editor/settings-sync" >Settings Sync</a> </li> <li > <a href="/docs/editor/userdefinedsnippets" >Snippets</a> </li> <li > <a href="/docs/editor/emmet" >Emmet</a> </li> <li > <a href="/docs/editor/command-line" >Command Line Interface</a> </li> <li > <a href="/docs/editor/workspaces" >Workspaces</a> </li> <li > <a href="/docs/editor/workspace-trust" >Workspace Trust</a> </li> <li > <a href="/docs/editor/multi-root-workspaces" >Multi-root Workspaces</a> </li> <li > <a href="/docs/editor/accessibility" >Accessibility</a> </li> <li > <a href="/docs/editor/voice" >Voice Interactions</a> </li> <li > <a href="/docs/editor/custom-layout" >Custom Layout</a> </li> <li > <a href="/docs/editor/port-forwarding" >Port Forwarding</a> </li> </ul> </li> <li class="panel collapsed"> <a class="area" role="button" href="#sourcecontrol-articles" data-parent="#main-nav" data-toggle="collapse">Source Control</a> <ul id="sourcecontrol-articles" class="collapse "> <li > <a href="/docs/sourcecontrol/overview" >Overview</a> </li> <li > <a href="/docs/sourcecontrol/intro-to-git" >Introduction to Git</a> </li> <li > <a href="/docs/sourcecontrol/github" >Collaborate on GitHub</a> </li> <li > <a href="/docs/sourcecontrol/faq" >FAQ</a> </li> </ul> </li> <li class="panel collapsed"> <a class="area" role="button" href="#terminal-articles" data-parent="#main-nav" data-toggle="collapse">Terminal</a> <ul id="terminal-articles" class="collapse "> <li > <a href="/docs/terminal/getting-started" >Getting Started Tutorial</a> </li> <li > <a href="/docs/terminal/basics" >Terminal Basics</a> </li> <li > <a href="/docs/terminal/profiles" >Terminal Profiles</a> </li> <li > <a href="/docs/terminal/shell-integration" >Shell Integration</a> </li> <li > <a href="/docs/terminal/appearance" >Appearance</a> </li> <li > <a href="/docs/terminal/advanced" >Advanced</a> </li> </ul> </li> <li class="panel collapsed"> <a class="area" role="button" href="#copilot-articles" data-parent="#main-nav" data-toggle="collapse">GitHub Copilot</a> <ul id="copilot-articles" class="collapse "> <li > <a href="/docs/copilot/overview" >Overview</a> </li> <li > <a href="/docs/copilot/copilot-vscode-features" >Copilot Cheat Sheet</a> </li> <li > <a href="/docs/copilot/setup" >Setup</a> </li> <li > <a href="/docs/copilot/getting-started" >Quickstart</a> </li> <li > <a href="/docs/copilot/ai-powered-suggestions" >Code Completions</a> </li> <li > <a href="/docs/copilot/copilot-chat" >Copilot Chat</a> </li> <li > <a href="/docs/copilot/getting-started-chat" >Copilot Chat Tutorial</a> </li> <li > <a href="/docs/copilot/copilot-edits" >Copilot Edits</a> </li> <li > <a href="/docs/copilot/prompt-crafting" >Best Practices</a> </li> <li > <a href="/docs/copilot/workspace-context" >Workspace Context</a> </li> <li > <a href="/docs/copilot/copilot-customization" >Customizing Copilot</a> </li> <li > <a href="/docs/copilot/copilot-extensibility-overview" >Copilot Extensibility</a> </li> <li > <a href="/docs/copilot/copilot-settings" >Settings Reference</a> </li> <li > <a href="/docs/copilot/faq" >FAQ</a> </li> </ul> </li> <li class="panel collapsed"> <a class="area" role="button" href="#languages-articles" data-parent="#main-nav" data-toggle="collapse">Languages</a> <ul id="languages-articles" class="collapse "> <li > <a href="/docs/languages/overview" >Overview</a> </li> <li > <a href="/docs/languages/javascript" >JavaScript</a> </li> <li > <a href="/docs/languages/json" >JSON</a> </li> <li > <a href="/docs/languages/html" >HTML</a> </li> <li > <a href="/docs/languages/css" >CSS, SCSS and Less</a> </li> <li > <a href="/docs/languages/typescript" >TypeScript</a> </li> <li > <a href="/docs/languages/markdown" >Markdown</a> </li> <li > <a href="/docs/languages/powershell" >PowerShell</a> </li> <li > <a href="/docs/languages/cpp" >C++</a> </li> <li > <a href="/docs/languages/java" >Java</a> </li> <li > <a href="/docs/languages/php" >PHP</a> </li> <li > <a href="/docs/languages/python" >Python</a> </li> <li > <a href="/docs/languages/julia" >Julia</a> </li> <li > <a href="/docs/languages/r" >R</a> </li> <li > <a href="/docs/languages/ruby" >Ruby</a> </li> <li > <a href="/docs/languages/rust" >Rust</a> </li> <li > <a href="/docs/languages/go" >Go</a> </li> <li > <a href="/docs/languages/tsql" >T-SQL</a> </li> <li > <a href="/docs/languages/csharp" >C#</a> </li> <li > <a href="/docs/languages/dotnet" >.NET</a> </li> <li > <a href="/docs/languages/polyglot" >Polyglot</a> </li> </ul> </li> <li class="panel collapsed"> <a class="area" role="button" href="#nodejs-articles" data-parent="#main-nav" data-toggle="collapse">Node.js / JavaScript</a> <ul id="nodejs-articles" class="collapse "> <li > <a href="/docs/nodejs/working-with-javascript" >Working with JavaScript</a> </li> <li > <a href="/docs/nodejs/nodejs-tutorial" >Node.js Tutorial</a> </li> <li > <a href="/docs/nodejs/nodejs-debugging" >Node.js Debugging</a> </li> <li > <a href="/docs/nodejs/nodejs-deployment" >Deploy Node.js Apps</a> </li> <li > <a href="/docs/nodejs/browser-debugging" >Browser Debugging</a> </li> <li > <a href="/docs/nodejs/angular-tutorial" >Angular Tutorial</a> </li> <li > <a href="/docs/nodejs/reactjs-tutorial" >React Tutorial</a> </li> <li > <a href="/docs/nodejs/vuejs-tutorial" >Vue Tutorial</a> </li> <li > <a href="/docs/nodejs/debugging-recipes" >Debugging Recipes</a> </li> <li > <a href="/docs/nodejs/profiling" >Performance Profiling</a> </li> <li > <a href="/docs/nodejs/extensions" >Extensions</a> </li> </ul> </li> <li class="panel collapsed"> <a class="area" role="button" href="#typescript-articles" data-parent="#main-nav" data-toggle="collapse">TypeScript</a> <ul id="typescript-articles" class="collapse "> <li > <a href="/docs/typescript/typescript-tutorial" >Tutorial</a> </li> <li > <a href="/docs/typescript/typescript-compiling" >Compiling</a> </li> <li > <a href="/docs/typescript/typescript-editing" >Editing</a> </li> <li > <a href="/docs/typescript/typescript-refactoring" >Refactoring</a> </li> <li > <a href="/docs/typescript/typescript-debugging" >Debugging</a> </li> </ul> </li> <li class="panel collapsed"> <a class="area" role="button" href="#python-articles" data-parent="#main-nav" data-toggle="collapse">Python</a> <ul id="python-articles" class="collapse "> <li > <a href="/docs/python/python-quick-start" >Quick Start</a> </li> <li > <a href="/docs/python/python-tutorial" >Tutorial</a> </li> <li > <a href="/docs/python/run" >Run Python Code</a> </li> <li > <a href="/docs/python/editing" >Editing Code</a> </li> <li > <a href="/docs/python/linting" >Linting</a> </li> <li > <a href="/docs/python/formatting" >Formatting</a> </li> <li > <a href="/docs/python/debugging" >Debugging</a> </li> <li > <a href="/docs/python/environments" >Environments</a> </li> <li > <a href="/docs/python/testing" >Testing</a> </li> <li > <a href="/docs/python/jupyter-support-py" >Python Interactive</a> </li> <li > <a href="/docs/python/tutorial-django" >Django Tutorial</a> </li> <li > <a href="/docs/python/tutorial-fastapi" >FastAPI Tutorial</a> </li> <li > <a href="/docs/python/tutorial-flask" >Flask Tutorial</a> </li> <li > <a href="/docs/python/tutorial-create-containers" >Create containers</a> </li> <li > <a href="/docs/python/python-on-azure" >Deploy Python Apps</a> </li> <li > <a href="/docs/python/python-web" >Python in the Web</a> </li> <li > <a href="/docs/python/settings-reference" >Settings Reference</a> </li> </ul> </li> <li class="panel collapsed"> <a class="area" role="button" href="#java-articles" data-parent="#main-nav" data-toggle="collapse">Java</a> <ul id="java-articles" class="collapse "> <li > <a href="/docs/java/java-tutorial" >Getting Started</a> </li> <li > <a href="/docs/java/java-editing" >Navigate and Edit</a> </li> <li > <a href="/docs/java/java-refactoring" >Refactoring</a> </li> <li > <a href="/docs/java/java-linting" >Formatting and Linting</a> </li> <li > <a href="/docs/java/java-project" >Project Management</a> </li> <li > <a href="/docs/java/java-build" >Build Tools</a> </li> <li > <a href="/docs/java/java-debugging" >Run and Debug</a> </li> <li > <a href="/docs/java/java-testing" >Testing</a> </li> <li > <a href="/docs/java/java-spring-boot" >Spring Boot</a> </li> <li > <a href="/docs/java/java-tomcat-jetty" >Application Servers</a> </li> <li > <a href="/docs/java/java-on-azure" >Deploy Java Apps</a> </li> <li > <a href="/docs/java/java-gui" >GUI Applications</a> </li> <li > <a href="/docs/java/extensions" >Extensions</a> </li> <li > <a href="/docs/java/java-faq" >FAQ</a> </li> </ul> </li> <li class="panel active expanded"> <a class="area" role="button" href="#cpp-articles" data-parent="#main-nav" data-toggle="collapse">C++</a> <ul id="cpp-articles" class="collapse in"> <li > <a href="/docs/cpp/introvideos-cpp" >Intro Videos</a> </li> <li > <a href="/docs/cpp/config-linux" >GCC on Linux</a> </li> <li class="active"> <a href="/docs/cpp/config-mingw" aria-label="Current Page: GCC on Windows">GCC on Windows</a> </li> <li > <a href="/docs/cpp/config-wsl" >GCC on Windows Subsystem for Linux</a> </li> <li > <a href="/docs/cpp/config-clang-mac" >Clang on macOS</a> </li> <li > <a href="/docs/cpp/config-msvc" >Microsoft C++ on Windows</a> </li> <li > <a href="/docs/cpp/build-with-cmake" >Build with CMake</a> </li> <li > <a href="/docs/cpp/cmake-linux" >CMake Tools on Linux</a> </li> <li > <a href="/docs/cpp/cmake-quickstart" >CMake Quick Start</a> </li> <li > <a href="/docs/cpp/cpp-ide" >Editing and Navigating</a> </li> <li > <a href="/docs/cpp/cpp-debug" >Debugging</a> </li> <li > <a href="/docs/cpp/cpp-refactoring" >Refactoring</a> </li> <li > <a href="/docs/cpp/launch-json-reference" >Configure debugging</a> </li> <li > <a href="/docs/cpp/customize-default-settings-cpp" >Settings</a> </li> <li > <a href="/docs/cpp/configure-intellisense" >Configure IntelliSense</a> </li> <li > <a href="/docs/cpp/configure-intellisense-crosscompilation" >Configure IntelliSense for cross-compiling</a> </li> <li > <a href="/docs/cpp/faq-cpp" >FAQ</a> </li> </ul> </li> <li class="panel collapsed"> <a class="area" role="button" href="#csharp-articles" data-parent="#main-nav" data-toggle="collapse">C#</a> <ul id="csharp-articles" class="collapse "> <li > <a href="/docs/csharp/introvideos-csharp" >Intro Videos</a> </li> <li > <a href="/docs/csharp/get-started" >Get Started</a> </li> <li > <a href="/docs/csharp/navigate-edit" >Navigate and Edit</a> </li> <li > <a href="/docs/csharp/intellicode" >IntelliCode</a> </li> <li > <a href="/docs/csharp/refactoring" >Refactoring</a> </li> <li > <a href="/docs/csharp/formatting-linting" >Formatting and Linting</a> </li> <li > <a href="/docs/csharp/project-management" >Project Management</a> </li> <li > <a href="/docs/csharp/build-tools" >Build Tools</a> </li> <li > <a href="/docs/csharp/package-management" >Package Management</a> </li> <li > <a href="/docs/csharp/debugging" >Run and Debug</a> </li> <li > <a href="/docs/csharp/testing" >Testing</a> </li> <li > <a href="/docs/csharp/cs-dev-kit-faq" >FAQ</a> </li> </ul> </li> <li class="panel collapsed"> <a class="area" role="button" href="#containers-articles" data-parent="#main-nav" data-toggle="collapse">Docker</a> <ul id="containers-articles" class="collapse "> <li > <a href="/docs/containers/overview" >Overview</a> </li> <li > <a href="/docs/containers/quickstart-node" >Node.js</a> </li> <li > <a href="/docs/containers/quickstart-python" >Python</a> </li> <li > <a href="/docs/containers/quickstart-aspnet-core" >ASP.NET Core</a> </li> <li > <a href="/docs/containers/debug-common" >Debug</a> </li> <li > <a href="/docs/containers/docker-compose" >Docker Compose</a> </li> <li > <a href="/docs/containers/quickstart-container-registries" >Registries</a> </li> <li > <a href="/docs/containers/app-service" >Deploy to Azure</a> </li> <li > <a href="/docs/containers/choosing-dev-environment" >Choose a dev environment</a> </li> <li > <a href="/docs/containers/reference" >Customize</a> </li> <li > <a href="/docs/containers/bridge-to-kubernetes" >Develop with Kubernetes</a> </li> <li > <a href="/docs/containers/troubleshooting" >Tips and Tricks</a> </li> </ul> </li> <li class="panel collapsed"> <a class="area" role="button" href="#datascience-articles" data-parent="#main-nav" data-toggle="collapse">Data Science</a> <ul id="datascience-articles" class="collapse "> <li > <a href="/docs/datascience/overview" >Overview</a> </li> <li > <a href="/docs/datascience/jupyter-notebooks" >Jupyter Notebooks</a> </li> <li > <a href="/docs/datascience/data-science-tutorial" >Data Science Tutorial</a> </li> <li > <a href="/docs/datascience/python-interactive" >Python Interactive</a> </li> <li > <a href="/docs/datascience/data-wrangler-quick-start" >Data Wrangler Quick Start</a> </li> <li > <a href="/docs/datascience/data-wrangler" >Data Wrangler</a> </li> <li > <a href="/docs/datascience/pytorch-support" >PyTorch Support</a> </li> <li > <a href="/docs/datascience/azure-machine-learning" >Azure Machine Learning</a> </li> <li > <a href="/docs/datascience/jupyter-kernel-management" >Manage Jupyter Kernels</a> </li> <li > <a href="/docs/datascience/notebooks-web" >Jupyter Notebooks on the web</a> </li> </ul> </li> <li class="panel collapsed"> <a class="area" role="button" href="#azure-articles" data-parent="#main-nav" data-toggle="collapse">Azure</a> <ul id="azure-articles" class="collapse "> <li > <a href="/docs/azure/overview" >Overview</a> </li> <li > <a href="/docs/azure/gettingstarted" >Getting Started</a> </li> <li > <a href="/docs/azure/deployment" >Deployment</a> </li> <li > <a href="/docs/azure/docker" >Docker</a> </li> <li > <a href="/docs/azure/aksextensions" >Azure Kubernetes Service</a> </li> <li > <a href="/docs/azure/kubernetes" >Kubernetes</a> </li> <li > <a href="/docs/azure/mongodb" >MongoDB</a> </li> <li > <a href="/docs/azure/remote-debugging" >Remote Debugging for Node.js</a> </li> </ul> </li> <li class="panel collapsed"> <a class="area" role="button" href="#remote-articles" data-parent="#main-nav" data-toggle="collapse">Remote</a> <ul id="remote-articles" class="collapse "> <li > <a href="/docs/remote/remote-overview" >Overview</a> </li> <li > <a href="/docs/remote/ssh" >SSH</a> </li> <li > <a href="/docs/remote/dev-containers" >Dev Containers</a> </li> <li > <a href="/docs/remote/wsl" >Windows Subsystem for Linux</a> </li> <li > <a href="/docs/remote/codespaces" >GitHub Codespaces</a> </li> <li > <a href="/docs/remote/vscode-server" >VS Code Server</a> </li> <li > <a href="/docs/remote/tunnels" >Tunnels</a> </li> <li > <a href="/docs/remote/ssh-tutorial" >SSH Tutorial</a> </li> <li > <a href="/docs/remote/wsl-tutorial" >WSL Tutorial</a> </li> <li > <a href="/docs/remote/troubleshooting" >Tips and Tricks</a> </li> <li > <a href="/docs/remote/faq" >FAQ</a> </li> </ul> </li> <li class="panel collapsed"> <a class="area" role="button" href="#devcontainers-articles" data-parent="#main-nav" data-toggle="collapse">Dev Containers</a> <ul id="devcontainers-articles" class="collapse "> <li > <a href="/docs/devcontainers/containers" >Overview</a> </li> <li > <a href="/docs/devcontainers/tutorial" >Tutorial</a> </li> <li > <a href="/docs/devcontainers/attach-container" >Attach to Container</a> </li> <li > <a href="/docs/devcontainers/create-dev-container" >Create a Dev Container</a> </li> <li > <a href="/docs/devcontainers/containers-advanced" >Advanced Containers</a> </li> <li > <a href="/docs/devcontainers/devcontainerjson-reference" >devcontainer.json</a> </li> <li > <a href="/docs/devcontainers/devcontainer-cli" >Dev Container CLI</a> </li> <li > <a href="/docs/devcontainers/tips-and-tricks" >Tips and Tricks</a> </li> <li > <a href="/docs/devcontainers/faq" >FAQ</a> </li> </ul> </li> </ul> </nav> <nav id="small-nav" aria-label="Topics" class="docs-nav hidden-md hidden-lg"> <label class="faux-h4" for="small-nav-dropdown">Topics</label> <select id="small-nav-dropdown" aria-label="topics"> <option value="/docs" >Overview</option> <optgroup label="Setup"> <option value="/docs/setup/setup-overview" >Overview</option> <option value="/docs/setup/linux" >Linux</option> <option value="/docs/setup/mac" >macOS</option> <option value="/docs/setup/windows" >Windows</option> <option value="/docs/setup/raspberry-pi" >Raspberry Pi</option> <option value="/docs/setup/network" >Network</option> <option value="/docs/setup/additional-components" >Additional Components</option> <option value="/docs/setup/enterprise" >Enterprise</option> <option value="/docs/setup/uninstall" >Uninstall</option> </optgroup> <optgroup label="Get Started"> <option value="/docs/getstarted/getting-started" >Tutorial</option> <option value="/docs/getstarted/introvideos" >Intro Videos</option> <option value="/docs/getstarted/tips-and-tricks" >Tips and Tricks</option> <option value="/docs/getstarted/userinterface" >User Interface</option> <option value="/docs/getstarted/themes" >Themes</option> <option value="/docs/getstarted/settings" >Settings</option> <option value="/docs/getstarted/keybindings" >Key Bindings</option> <option value="/docs/getstarted/locales" >Display Language</option> <option value="/docs/getstarted/telemetry" >Telemetry</option> <option value="/docs/getstarted/educators-and-students" >Educators & Students</option> </optgroup> <optgroup label="User Guide"> <option value="/docs/editor/codebasics" >Basic Editing</option> <option value="/docs/editor/extension-marketplace" >Extension Marketplace</option> <option value="/docs/editor/intellisense" >IntelliSense</option> <option value="/docs/editor/editingevolved" >Code Navigation</option> <option value="/docs/editor/refactoring" >Refactoring</option> <option value="/docs/editor/debugging" >Debugging</option> <option value="/docs/editor/testing" >Testing</option> <option value="/docs/editor/vscode-web" >VS Code for the Web</option> <option value="/docs/editor/tasks" >Tasks</option> <option value="/docs/editor/profiles" >Profiles</option> <option value="/docs/editor/settings-sync" >Settings Sync</option> <option value="/docs/editor/userdefinedsnippets" >Snippets</option> <option value="/docs/editor/emmet" >Emmet</option> <option value="/docs/editor/command-line" >Command Line Interface</option> <option value="/docs/editor/workspaces" >Workspaces</option> <option value="/docs/editor/workspace-trust" >Workspace Trust</option> <option value="/docs/editor/multi-root-workspaces" >Multi-root Workspaces</option> <option value="/docs/editor/accessibility" >Accessibility</option> <option value="/docs/editor/voice" >Voice Interactions</option> <option value="/docs/editor/custom-layout" >Custom Layout</option> <option value="/docs/editor/port-forwarding" >Port Forwarding</option> </optgroup> <optgroup label="Source Control"> <option value="/docs/sourcecontrol/overview" >Overview</option> <option value="/docs/sourcecontrol/intro-to-git" >Introduction to Git</option> <option value="/docs/sourcecontrol/github" >Collaborate on GitHub</option> <option value="/docs/sourcecontrol/faq" >FAQ</option> </optgroup> <optgroup label="Terminal"> <option value="/docs/terminal/getting-started" >Getting Started Tutorial</option> <option value="/docs/terminal/basics" >Terminal Basics</option> <option value="/docs/terminal/profiles" >Terminal Profiles</option> <option value="/docs/terminal/shell-integration" >Shell Integration</option> <option value="/docs/terminal/appearance" >Appearance</option> <option value="/docs/terminal/advanced" >Advanced</option> </optgroup> <optgroup label="GitHub Copilot"> <option value="/docs/copilot/overview" >Overview</option> <option value="/docs/copilot/copilot-vscode-features" >Copilot Cheat Sheet</option> <option value="/docs/copilot/setup" >Setup</option> <option value="/docs/copilot/getting-started" >Quickstart</option> <option value="/docs/copilot/ai-powered-suggestions" >Code Completions</option> <option value="/docs/copilot/copilot-chat" >Copilot Chat</option> <option value="/docs/copilot/getting-started-chat" >Copilot Chat Tutorial</option> <option value="/docs/copilot/copilot-edits" >Copilot Edits</option> <option value="/docs/copilot/prompt-crafting" >Best Practices</option> <option value="/docs/copilot/workspace-context" >Workspace Context</option> <option value="/docs/copilot/copilot-customization" >Customizing Copilot</option> <option value="/docs/copilot/copilot-extensibility-overview" >Copilot Extensibility</option> <option value="/docs/copilot/copilot-settings" >Settings Reference</option> <option value="/docs/copilot/faq" >FAQ</option> </optgroup> <optgroup label="Languages"> <option value="/docs/languages/overview" >Overview</option> <option value="/docs/languages/javascript" >JavaScript</option> <option value="/docs/languages/json" >JSON</option> <option value="/docs/languages/html" >HTML</option> <option value="/docs/languages/css" >CSS, SCSS and Less</option> <option value="/docs/languages/typescript" >TypeScript</option> <option value="/docs/languages/markdown" >Markdown</option> <option value="/docs/languages/powershell" >PowerShell</option> <option value="/docs/languages/cpp" >C++</option> <option value="/docs/languages/java" >Java</option> <option value="/docs/languages/php" >PHP</option> <option value="/docs/languages/python" >Python</option> <option value="/docs/languages/julia" >Julia</option> <option value="/docs/languages/r" >R</option> <option value="/docs/languages/ruby" >Ruby</option> <option value="/docs/languages/rust" >Rust</option> <option value="/docs/languages/go" >Go</option> <option value="/docs/languages/tsql" >T-SQL</option> <option value="/docs/languages/csharp" >C#</option> <option value="/docs/languages/dotnet" >.NET</option> <option value="/docs/languages/polyglot" >Polyglot</option> </optgroup> <optgroup label="Node.js / JavaScript"> <option value="/docs/nodejs/working-with-javascript" >Working with JavaScript</option> <option value="/docs/nodejs/nodejs-tutorial" >Node.js Tutorial</option> <option value="/docs/nodejs/nodejs-debugging" >Node.js Debugging</option> <option value="/docs/nodejs/nodejs-deployment" >Deploy Node.js Apps</option> <option value="/docs/nodejs/browser-debugging" >Browser Debugging</option> <option value="/docs/nodejs/angular-tutorial" >Angular Tutorial</option> <option value="/docs/nodejs/reactjs-tutorial" >React Tutorial</option> <option value="/docs/nodejs/vuejs-tutorial" >Vue Tutorial</option> <option value="/docs/nodejs/debugging-recipes" >Debugging Recipes</option> <option value="/docs/nodejs/profiling" >Performance Profiling</option> <option value="/docs/nodejs/extensions" >Extensions</option> </optgroup> <optgroup label="TypeScript"> <option value="/docs/typescript/typescript-tutorial" >Tutorial</option> <option value="/docs/typescript/typescript-compiling" >Compiling</option> <option value="/docs/typescript/typescript-editing" >Editing</option> <option value="/docs/typescript/typescript-refactoring" >Refactoring</option> <option value="/docs/typescript/typescript-debugging" >Debugging</option> </optgroup> <optgroup label="Python"> <option value="/docs/python/python-quick-start" >Quick Start</option> <option value="/docs/python/python-tutorial" >Tutorial</option> <option value="/docs/python/run" >Run Python Code</option> <option value="/docs/python/editing" >Editing Code</option> <option value="/docs/python/linting" >Linting</option> <option value="/docs/python/formatting" >Formatting</option> <option value="/docs/python/debugging" >Debugging</option> <option value="/docs/python/environments" >Environments</option> <option value="/docs/python/testing" >Testing</option> <option value="/docs/python/jupyter-support-py" >Python Interactive</option> <option value="/docs/python/tutorial-django" >Django Tutorial</option> <option value="/docs/python/tutorial-fastapi" >FastAPI Tutorial</option> <option value="/docs/python/tutorial-flask" >Flask Tutorial</option> <option value="/docs/python/tutorial-create-containers" >Create containers</option> <option value="/docs/python/python-on-azure" >Deploy Python Apps</option> <option value="/docs/python/python-web" >Python in the Web</option> <option value="/docs/python/settings-reference" >Settings Reference</option> </optgroup> <optgroup label="Java"> <option value="/docs/java/java-tutorial" >Getting Started</option> <option value="/docs/java/java-editing" >Navigate and Edit</option> <option value="/docs/java/java-refactoring" >Refactoring</option> <option value="/docs/java/java-linting" >Formatting and Linting</option> <option value="/docs/java/java-project" >Project Management</option> <option value="/docs/java/java-build" >Build Tools</option> <option value="/docs/java/java-debugging" >Run and Debug</option> <option value="/docs/java/java-testing" >Testing</option> <option value="/docs/java/java-spring-boot" >Spring Boot</option> <option value="/docs/java/java-tomcat-jetty" >Application Servers</option> <option value="/docs/java/java-on-azure" >Deploy Java Apps</option> <option value="/docs/java/java-gui" >GUI Applications</option> <option value="/docs/java/extensions" >Extensions</option> <option value="/docs/java/java-faq" >FAQ</option> </optgroup> <optgroup label="C++"> <option value="/docs/cpp/introvideos-cpp" >Intro Videos</option> <option value="/docs/cpp/config-linux" >GCC on Linux</option> <option value="/docs/cpp/config-mingw" selected>GCC on Windows</option> <option value="/docs/cpp/config-wsl" >GCC on Windows Subsystem for Linux</option> <option value="/docs/cpp/config-clang-mac" >Clang on macOS</option> <option value="/docs/cpp/config-msvc" >Microsoft C++ on Windows</option> <option value="/docs/cpp/build-with-cmake" >Build with CMake</option> <option value="/docs/cpp/cmake-linux" >CMake Tools on Linux</option> <option value="/docs/cpp/cmake-quickstart" >CMake Quick Start</option> <option value="/docs/cpp/cpp-ide" >Editing and Navigating</option> <option value="/docs/cpp/cpp-debug" >Debugging</option> <option value="/docs/cpp/cpp-refactoring" >Refactoring</option> <option value="/docs/cpp/launch-json-reference" >Configure debugging</option> <option value="/docs/cpp/customize-default-settings-cpp" >Settings</option> <option value="/docs/cpp/configure-intellisense" >Configure IntelliSense</option> <option value="/docs/cpp/configure-intellisense-crosscompilation" >Configure IntelliSense for cross-compiling</option> <option value="/docs/cpp/faq-cpp" >FAQ</option> </optgroup> <optgroup label="C#"> <option value="/docs/csharp/introvideos-csharp" >Intro Videos</option> <option value="/docs/csharp/get-started" >Get Started</option> <option value="/docs/csharp/navigate-edit" >Navigate and Edit</option> <option value="/docs/csharp/intellicode" >IntelliCode</option> <option value="/docs/csharp/refactoring" >Refactoring</option> <option value="/docs/csharp/formatting-linting" >Formatting and Linting</option> <option value="/docs/csharp/project-management" >Project Management</option> <option value="/docs/csharp/build-tools" >Build Tools</option> <option value="/docs/csharp/package-management" >Package Management</option> <option value="/docs/csharp/debugging" >Run and Debug</option> <option value="/docs/csharp/testing" >Testing</option> <option value="/docs/csharp/cs-dev-kit-faq" >FAQ</option> </optgroup> <optgroup label="Docker"> <option value="/docs/containers/overview" >Overview</option> <option value="/docs/containers/quickstart-node" >Node.js</option> <option value="/docs/containers/quickstart-python" >Python</option> <option value="/docs/containers/quickstart-aspnet-core" >ASP.NET Core</option> <option value="/docs/containers/debug-common" >Debug</option> <option value="/docs/containers/docker-compose" >Docker Compose</option> <option value="/docs/containers/quickstart-container-registries" >Registries</option> <option value="/docs/containers/app-service" >Deploy to Azure</option> <option value="/docs/containers/choosing-dev-environment" >Choose a dev environment</option> <option value="/docs/containers/reference" >Customize</option> <option value="/docs/containers/bridge-to-kubernetes" >Develop with Kubernetes</option> <option value="/docs/containers/troubleshooting" >Tips and Tricks</option> </optgroup> <optgroup label="Data Science"> <option value="/docs/datascience/overview" >Overview</option> <option value="/docs/datascience/jupyter-notebooks" >Jupyter Notebooks</option> <option value="/docs/datascience/data-science-tutorial" >Data Science Tutorial</option> <option value="/docs/datascience/python-interactive" >Python Interactive</option> <option value="/docs/datascience/data-wrangler-quick-start" >Data Wrangler Quick Start</option> <option value="/docs/datascience/data-wrangler" >Data Wrangler</option> <option value="/docs/datascience/pytorch-support" >PyTorch Support</option> <option value="/docs/datascience/azure-machine-learning" >Azure Machine Learning</option> <option value="/docs/datascience/jupyter-kernel-management" >Manage Jupyter Kernels</option> <option value="/docs/datascience/notebooks-web" >Jupyter Notebooks on the web</option> </optgroup> <optgroup label="Azure"> <option value="/docs/azure/overview" >Overview</option> <option value="/docs/azure/gettingstarted" >Getting Started</option> <option value="/docs/azure/deployment" >Deployment</option> <option value="/docs/azure/docker" >Docker</option> <option value="/docs/azure/aksextensions" >Azure Kubernetes Service</option> <option value="/docs/azure/kubernetes" >Kubernetes</option> <option value="/docs/azure/mongodb" >MongoDB</option> <option value="/docs/azure/remote-debugging" >Remote Debugging for Node.js</option> </optgroup> <optgroup label="Remote"> <option value="/docs/remote/remote-overview" >Overview</option> <option value="/docs/remote/ssh" >SSH</option> <option value="/docs/remote/dev-containers" >Dev Containers</option> <option value="/docs/remote/wsl" >Windows Subsystem for Linux</option> <option value="/docs/remote/codespaces" >GitHub Codespaces</option> <option value="/docs/remote/vscode-server" >VS Code Server</option> <option value="/docs/remote/tunnels" >Tunnels</option> <option value="/docs/remote/ssh-tutorial" >SSH Tutorial</option> <option value="/docs/remote/wsl-tutorial" >WSL Tutorial</option> <option value="/docs/remote/troubleshooting" >Tips and Tricks</option> <option value="/docs/remote/faq" >FAQ</option> </optgroup> <optgroup label="Dev Containers"> <option value="/docs/devcontainers/containers" >Overview</option> <option value="/docs/devcontainers/tutorial" >Tutorial</option> <option value="/docs/devcontainers/attach-container" >Attach to Container</option> <option value="/docs/devcontainers/create-dev-container" >Create a Dev Container</option> <option value="/docs/devcontainers/containers-advanced" >Advanced Containers</option> <option value="/docs/devcontainers/devcontainerjson-reference" >devcontainer.json</option> <option value="/docs/devcontainers/devcontainer-cli" >Dev Container CLI</option> <option value="/docs/devcontainers/tips-and-tricks" >Tips and Tricks</option> <option value="/docs/devcontainers/faq" >FAQ</option> </optgroup> </select> </nav> </div> <!-- small right nav --> <div class="col-xs-12 visible-xs"> <nav aria-labelledby="small-right-nav-label" class="small-nav docs-nav updates-nav"> <label class="faux-h4" for="small-right-nav-dropdown" id="small-right-nav-label">In this article</label> <select id="small-right-nav-dropdown" class="small-nav-select" aria-label="Sections"> <option value="#_prerequisites">Prerequisites</option> <option value="#_installing-the-mingww64-toolchain">Installing the MinGW-w64 toolchain</option> <option value="#_create-a-hello-world-app">Create a Hello World app</option> <option value="#_explore-intellisense">Explore IntelliSense</option> <option value="#_run-helloworldcpp">Run helloworld.cpp</option> <option value="#_debug-helloworldcpp">Debug helloworld.cpp</option> <option value="#_explore-the-debugger">Explore the debugger</option> <option value="#_customize-debugging-with-launchjson">Customize debugging with launch.json</option> <option value="#_adding-additional-cc-settings">Adding additional C/C++ settings</option> <option value="#_troubleshooting">Troubleshooting</option> <option value="#_next-steps">Next steps</option> </select> </nav> </div> <!-- main content --> <main class="col-xs-12 col-sm-9 col-md-8 body"> <div class="edit-github pull-right"> <a href="https://vscode.dev/github/microsoft/vscode-docs/blob/main/docs/cpp/config-mingw.md" class="btn btn-default" title="Edit this document in vscode.dev"> <span class="glyphicon glyphicon-pencil"></span> <span class="hidden-xs">Edit</span> </a> </div> <h1>Using GCC with MinGW</h1> <p>In this tutorial, you configure Visual Studio Code to use the GCC C++ compiler (g++) and GDB debugger from <a href="http://mingw-w64.org" class="external-link" target="_blank">mingw-w64</a> to create programs that run on Windows. After configuring VS Code, you will compile, run, and debug a Hello World program.</p> <p>This tutorial does not teach you about GCC, GDB, minGW-w64, or the C++ language. For those subjects, there are many good resources available on the Web.</p> <p>If you have any problems, feel free to file an issue for this tutorial in the <a href="https://github.com/microsoft/vscode-docs/issues/new" class="external-link" target="_blank">VS Code documentation repository</a>.</p> <h2 id="_prerequisites" data-needslink="_prerequisites">Prerequisites</h2> <p>To successfully complete this tutorial, you must do the following steps:</p> <ol> <li> <p>Install <a href="/download">Visual Studio Code</a>.</p> </li> <li> <p>Install the <a href="https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools" class="external-link" target="_blank">C/C++ extension for VS Code</a>. You can install the C/C++ extension by searching for 'C++' in the Extensions view (<span class="dynamic-keybinding" data-commandId="workbench.view.extensions" data-osx="鈬р寴X" data-win="Ctrl+Shift+X" data-linux="Ctrl+Shift+X"><span class="keybinding">鈬р寴X</span> (Windows, Linux <span class="keybinding">Ctrl+Shift+X</span>)</span>).</p> <p><img src="/assets/docs/cpp/cpp/cpp-extension.png" alt="C/C++ extension" loading="lazy"></p> </li> </ol> <h2 id="_installing-the-mingww64-toolchain" data-needslink="_installing-the-mingww64-toolchain">Installing the MinGW-w64 toolchain</h2> <p>Get the latest version of MinGW-w64 via <a href="https://www.msys2.org/" class="external-link" target="_blank">MSYS2</a>, which provides up-to-date native builds of GCC, MinGW-w64, and other helpful C++ tools and libraries. This will provide you with the necessary tools to compile your code, debug it, and configure it to work with <a href="/docs/editor/intellisense">IntelliSense</a>.</p> <p>To install the MinGW-w64 toolchain, check out this video or follow the steps below:</p> <iframe width="560" height="315" src="https://www.youtube-nocookie.com/embed/oC69vlWofJQ" title="Installing MinGW to build C++ code on Windows" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe> <ol> <li> <p>You can download the latest installer from the MSYS2 page or use this <a href="https://github.com/msys2/msys2-installer/releases/download/2024-01-13/msys2-x86_64-20240113.exe" class="external-link" target="_blank"><strong>direct link to the installer</strong></a>.</p> </li> <li> <p>Run the installer and follow the steps of the installation wizard. Note that MSYS2 requires 64 bit Windows 8.1 or newer.</p> </li> <li> <p>In the wizard, choose your desired Installation Folder. Record this directory for later. In most cases, the recommended directory is acceptable. The same applies when you get to setting the start menu shortcuts step. When complete, ensure the <strong>Run MSYS2 now</strong> box is checked and select <strong>Finish</strong>. This will open a MSYS2 terminal window for you.</p> </li> <li> <p>In this terminal, install the MinGW-w64 toolchain by running the following command:</p> <pre class="shiki" style="background-color: #1e1e1e"><code><span class="line"><span style="color: #BBBBBB">pacman -S --needed base-devel mingw-w64-ucrt-x86_64-toolchain</span></span> <span class="line"></span></code></pre> </li> <li> <p>Accept the default number of packages in the <code>toolchain</code> group by pressing <span class="keybinding">Enter</span>.</p> <p><img src="/assets/docs/cpp/cpp/cpp-install-MSYS2-toolchain.png" alt="MYSS2 Installer" loading="lazy"></p> </li> <li> <p>Enter <code>Y</code> when prompted whether to proceed with the installation.</p> </li> <li> <p>Add the path of your MinGW-w64 <code>bin</code> folder to the Windows <code>PATH</code> environment variable by using the following steps:</p> <ol> <li>In the Windows search bar, type <strong>Settings</strong> to open your Windows Settings.</li> <li>Search for <strong>Edit environment variables for your account</strong>.</li> <li>In your <strong>User variables</strong>, select the <code>Path</code> variable and then select <strong>Edit</strong>.</li> <li>Select <strong>New</strong> and add the MinGW-w64 destination folder you recorded during the installation process to the list. If you used the default settings above, then this will be the path: <code>C:\msys64\ucrt64\bin</code>.</li> <li>Select <strong>OK</strong>, and then select <strong>OK</strong> again in the <strong>Environment Variables</strong> window to update the <code>PATH</code> environment variable. You have to reopen any console windows for the updated <code>PATH</code> environment variable to be available.</li> </ol> </li> </ol> <h3 id="_check-your-mingw-installation" data-needslink="_check-your-mingw-installation">Check your MinGW installation</h3> <p>To check that your MinGW-w64 tools are correctly installed and available, open a <strong>new</strong> Command Prompt and type:</p> <pre class="shiki" style="background-color: #1e1e1e"><code><span class="line"><span style="color: #BBBBBB">gcc --version</span></span> <span class="line"><span style="color: #BBBBBB">g++ --version</span></span> <span class="line"><span style="color: #BBBBBB">gdb --version</span></span> <span class="line"></span></code></pre> <p>You should see output that states which versions of GCC, g++ and GDB you have installed. If this is not the case:</p> <ol> <li>Make sure your PATH variable entry matches the MinGW-w64 binary location where the toolchain was installed. If the compilers do not exist at that PATH entry, make sure you followed the previous instructions.</li> <li>If <code>gcc</code> has the correct output but not <code>gdb</code>, then you need to install the packages you are missing from the MinGW-w64 toolset. <ul> <li>If on compilation you are getting the "The value of miDebuggerPath is invalid." message, one cause can be you are missing the <code>mingw-w64-gdb</code> package.</li> </ul> </li> </ol> <h2 id="_create-a-hello-world-app" data-needslink="_create-a-hello-world-app">Create a Hello World app</h2> <p>First, lets get a project set up.</p> <ol> <li>Launch a Windows command prompt (Enter <strong>Windows command prompt</strong> in the Windows search bar).</li> <li>Run the following commands. These will create an empty folder called <code>projects</code> where you can place all your VS Code projects. There, the next commands will create and navigate to a subfolder called <code>helloworld</code>. From there, you will open <code>helloworld</code> directly in VS Code.</li> </ol> <pre class="shiki" style="background-color: #1e1e1e"><code><span class="line"><span style="color: #569CD6">mkdir</span><span style="color: #BBBBBB"> projects</span></span> <span class="line"><span style="color: #569CD6">cd</span><span style="color: #BBBBBB"> projects</span></span> <span class="line"><span style="color: #569CD6">mkdir</span><span style="color: #BBBBBB"> helloworld</span></span> <span class="line"><span style="color: #569CD6">cd</span><span style="color: #BBBBBB"> helloworld</span></span> <span class="line"><span style="color: #BBBBBB">code .</span></span> <span class="line"></span></code></pre> <p>The "code ." command opens VS Code in the current working folder, which becomes your "workspace". Accept the <a href="/docs/editor/workspace-trust">Workspace Trust</a> dialog by selecting <strong>Yes, I trust the authors</strong> since this is a folder you created.</p> <p>As you go through the tutorial, you will see three files created in a <code>.vscode</code> folder in the workspace:</p> <ul> <li><code>tasks.json</code> (build instructions)</li> <li><code>launch.json</code> (debugger settings)</li> <li><code>c_cpp_properties.json</code> (compiler path and IntelliSense settings)</li> </ul> <h3 id="_add-a-hello-world-source-code-file" data-needslink="_add-a-hello-world-source-code-file">Add a Hello World source code file</h3> <p>In the File Explorer title bar, select the <strong>New File</strong> button and name the file <code>helloworld.cpp</code>.</p> <p><img src="/assets/docs/cpp/mingw/new-file-button.png" alt="New File title bar button" loading="lazy"></p> <h3 id="_add-hello-world-source-code" data-needslink="_add-hello-world-source-code">Add hello world source code</h3> <p>Now paste in this source code:</p> <pre class="shiki" style="background-color: #1e1e1e"><code><span class="line"><span style="color: #C586C0">#include</span><span style="color: #569CD6"> </span><span style="color: #CE9178"><iostream></span></span> <span class="line"><span style="color: #C586C0">#include</span><span style="color: #569CD6"> </span><span style="color: #CE9178"><vector></span></span> <span class="line"><span style="color: #C586C0">#include</span><span style="color: #569CD6"> </span><span style="color: #CE9178"><string></span></span> <span class="line"></span> <span class="line"><span style="color: #C586C0">using</span><span style="color: #BBBBBB"> </span><span style="color: #569CD6">namespace</span><span style="color: #BBBBBB"> </span><span style="color: #4EC9B0">std</span><span style="color: #BBBBBB">;</span></span> <span class="line"></span> <span class="line"><span style="color: #569CD6">int</span><span style="color: #BBBBBB"> </span><span style="color: #DCDCAA">main</span><span style="color: #BBBBBB">()</span></span> <span class="line"><span style="color: #BBBBBB">{</span></span> <span class="line"><span style="color: #BBBBBB"> vector</span><span style="color: #D4D4D4"><</span><span style="color: #BBBBBB">string</span><span style="color: #D4D4D4">></span><span style="color: #BBBBBB"> msg {</span><span style="color: #CE9178">"Hello"</span><span style="color: #BBBBBB">, </span><span style="color: #CE9178">"C++"</span><span style="color: #BBBBBB">, </span><span style="color: #CE9178">"World"</span><span style="color: #BBBBBB">, </span><span style="color: #CE9178">"from"</span><span style="color: #BBBBBB">, </span><span style="color: #CE9178">"VS Code"</span><span style="color: #BBBBBB">, </span><span style="color: #CE9178">"and the C++ extension!"</span><span style="color: #BBBBBB">};</span></span> <span class="line"></span> <span class="line"><span style="color: #BBBBBB"> </span><span style="color: #C586C0">for</span><span style="color: #BBBBBB"> (</span><span style="color: #569CD6">const</span><span style="color: #BBBBBB"> string</span><span style="color: #D4D4D4">&</span><span style="color: #BBBBBB"> word : msg)</span></span> <span class="line"><span style="color: #BBBBBB"> {</span></span> <span class="line"><span style="color: #BBBBBB"> cout </span><span style="color: #D4D4D4"><<</span><span style="color: #BBBBBB"> word </span><span style="color: #D4D4D4"><<</span><span style="color: #BBBBBB"> </span><span style="color: #CE9178">" "</span><span style="color: #BBBBBB">;</span></span> <span class="line"><span style="color: #BBBBBB"> }</span></span> <span class="line"><span style="color: #BBBBBB"> cout </span><span style="color: #D4D4D4"><<</span><span style="color: #BBBBBB"> endl;</span></span> <span class="line"><span style="color: #BBBBBB">}</span></span> <span class="line"></span></code></pre> <p>Now press <span class="dynamic-keybinding" data-commandId="workbench.action.files.save" data-osx="鈱楽" data-win="Ctrl+S" data-linux="Ctrl+S"><span class="keybinding">鈱楽</span> (Windows, Linux <span class="keybinding">Ctrl+S</span>)</span> to save the file. Notice how the file you just added appears in the <strong>File Explorer</strong> view (<span class="dynamic-keybinding" data-commandId="workbench.view.explorer" data-osx="鈬р寴E" data-win="Ctrl+Shift+E" data-linux="Ctrl+Shift+E"><span class="keybinding">鈬р寴E</span> (Windows, Linux <span class="keybinding">Ctrl+Shift+E</span>)</span>) in the side bar of VS Code:</p> <p><img src="/assets/docs/cpp/mingw/file-explorer-mingw.png" alt="File Explorer" loading="lazy"></p> <p>You can also enable <a href="/docs/editor/codebasics#_save-auto-save">Auto Save</a> to automatically save your file changes, by selecting <strong>File</strong> > <strong>Auto Save</strong>. You can find out more about the other views in the VS Code <a href="/docs/getstarted/userinterface">User Interface documentation</a>.</p> <blockquote><p><strong>Note</strong>: When you save or open a C++ file, you may see a notification from the C/C++ extension about the availability of an Insiders version, which lets you test new features and fixes. You can ignore this notification by selecting the <code>X</code> (<strong>Clear Notification</strong>).</p> </blockquote><h2 id="_explore-intellisense" data-needslink="_explore-intellisense">Explore IntelliSense</h2> <p><a href="/docs/editor/intellisense">IntelliSense</a> is a tool to help you code faster and more efficiently by adding code editing features such as code completion, parameter info, quick info, and member lists.</p> <p>To see IntelliSense in action, hover over <code>vector</code> or <code>string</code> to see their type information. If you type <code>msg.</code> in line 10, you can see a completion list of recommended member functions to call, all generated by IntelliSense:</p> <p><img src="/assets/docs/cpp/wsl/msg-intellisense.png" alt="Statement completion IntelliSense" loading="lazy"></p> <p>You can press the <span class="keybinding">Tab</span> key to insert a selected member. If you then add open parenthesis, IntelliSense will show information on which arguments are required.</p> <p>If IntelliSense is not already configured, open the Command Palette (<span class="dynamic-keybinding" data-commandId="workbench.action.showCommands" data-osx="鈬р寴P" data-win="Ctrl+Shift+P" data-linux="Ctrl+Shift+P"><span class="keybinding">鈬р寴P</span> (Windows, Linux <span class="keybinding">Ctrl+Shift+P</span>)</span>) and enter <strong>Select IntelliSense Configuration</strong>. From the dropdown of compilers, select <code>Use gcc.exe</code> to configure. More information can be found in the <a href="/docs/languages/cpp#_intellisense-configuration">IntelliSense configuration documentation</a>.</p> <h2 id="_run-helloworldcpp" data-needslink="_run-helloworldcpp">Run helloworld.cpp</h2> <p>Remember, the C++ extension uses the C++ compiler you have installed on your machine to build your program. Make sure you have completed the "Installing the MinGW-w64 toolchain" step before attempting to run and debug <code>helloworld.cpp</code> in VS Code.</p> <ol> <li> <p>Open <code>helloworld.cpp</code> so that it is the active file.</p> </li> <li> <p>Press the play button in the top right corner of the editor.</p> <p><img src="/assets/docs/cpp/playbutton/run-play-button.png" alt="Screenshot of helloworld.cpp and play button" loading="lazy"></p> </li> <li> <p>Choose <strong>C/C++: g++.exe build and debug active file</strong> from the list of detected compilers on your system.</p> <p><img src="/assets/docs/cpp/playbutton/select-gcc-compiler.png" alt="C++ debug configuration dropdown" loading="lazy"></p> </li> </ol> <p>You'll only be asked to choose a compiler the first time you run <code>helloworld.cpp</code>. This compiler will be set as the "default" compiler in <code>tasks.json</code> file.</p> <ol start="4"> <li> <p>After the build succeeds, your program's output will appear in the integrated <strong>Terminal</strong>.</p> <p><img src="/assets/docs/cpp/playbutton/helloworld-terminal-output.png" alt="screenshot of program output" loading="lazy"></p> </li> </ol> <p>Congratulations! You've just run your first C++ program in VS Code!</p> <h3 id="_understanding-tasksjson" data-needslink="_understanding-tasksjson">Understanding tasks.json</h3> <p>The first time you run your program, the C++ extension creates a <code>tasks.json</code> file, which you'll find in your project's <code>.vscode</code> folder. <code>tasks.json</code> stores your build configurations.</p> <p>Your new <code>tasks.json</code> file should look similar to the JSON below:</p> <pre class="shiki" style="background-color: #1e1e1e"><code><span class="line"><span style="color: #BBBBBB">{</span></span> <span class="line"><span style="color: #BBBBBB"> </span><span style="color: #9CDCFE">"tasks"</span><span style="color: #BBBBBB">: [</span></span> <span class="line"><span style="color: #BBBBBB"> {</span></span> <span class="line"><span style="color: #BBBBBB"> </span><span style="color: #9CDCFE">"type"</span><span style="color: #BBBBBB">: </span><span style="color: #CE9178">"cppbuild"</span><span style="color: #BBBBBB">,</span></span> <span class="line"><span style="color: #BBBBBB"> </span><span style="color: #9CDCFE">"label"</span><span style="color: #BBBBBB">: </span><span style="color: #CE9178">"C/C++: g++.exe build active file"</span><span style="color: #BBBBBB">,</span></span> <span class="line"><span style="color: #BBBBBB"> </span><span style="color: #9CDCFE">"command"</span><span style="color: #BBBBBB">: </span><span style="color: #CE9178">"C:</span><span style="color: #D7BA7D">\\</span><span style="color: #CE9178">msys64</span><span style="color: #D7BA7D">\\</span><span style="color: #CE9178">ucrt64</span><span style="color: #D7BA7D">\\</span><span style="color: #CE9178">bin</span><span style="color: #D7BA7D">\\</span><span style="color: #CE9178">g++.exe"</span><span style="color: #BBBBBB">,</span></span> <span class="line"><span style="color: #BBBBBB"> </span><span style="color: #9CDCFE">"args"</span><span style="color: #BBBBBB">: [</span></span> <span class="line"><span style="color: #BBBBBB"> </span><span style="color: #CE9178">"-fdiagnostics-color=always"</span><span style="color: #BBBBBB">,</span></span> <span class="line"><span style="color: #BBBBBB"> </span><span style="color: #CE9178">"-g"</span><span style="color: #BBBBBB">,</span></span> <span class="line"><span style="color: #BBBBBB"> </span><span style="color: #CE9178">"${file}"</span><span style="color: #BBBBBB">,</span></span> <span class="line"><span style="color: #BBBBBB"> </span><span style="color: #CE9178">"-o"</span><span style="color: #BBBBBB">,</span></span> <span class="line"><span style="color: #BBBBBB"> </span><span style="color: #CE9178">"${fileDirname}</span><span style="color: #D7BA7D">\\</span><span style="color: #CE9178">${fileBasenameNoExtension}.exe"</span></span> <span class="line"><span style="color: #BBBBBB"> ],</span></span> <span class="line"><span style="color: #BBBBBB"> </span><span style="color: #9CDCFE">"options"</span><span style="color: #BBBBBB">: {</span></span> <span class="line"><span style="color: #BBBBBB"> </span><span style="color: #9CDCFE">"cwd"</span><span style="color: #BBBBBB">: </span><span style="color: #CE9178">"${fileDirname}"</span></span> <span class="line"><span style="color: #BBBBBB"> },</span></span> <span class="line"><span style="color: #BBBBBB"> </span><span style="color: #9CDCFE">"problemMatcher"</span><span style="color: #BBBBBB">: [</span><span style="color: #CE9178">"$gcc"</span><span style="color: #BBBBBB">],</span></span> <span class="line"><span style="color: #BBBBBB"> </span><span style="color: #9CDCFE">"group"</span><span style="color: #BBBBBB">: {</span></span> <span class="line"><span style="color: #BBBBBB"> </span><span style="color: #9CDCFE">"kind"</span><span style="color: #BBBBBB">: </span><span style="color: #CE9178">"build"</span><span style="color: #BBBBBB">,</span></span> <span class="line"><span style="color: #BBBBBB"> </span><span style="color: #9CDCFE">"isDefault"</span><span style="color: #BBBBBB">: </span><span style="color: #569CD6">true</span></span> <span class="line"><span style="color: #BBBBBB"> },</span></span> <span class="line"><span style="color: #BBBBBB"> </span><span style="color: #9CDCFE">"detail"</span><span style="color: #BBBBBB">: </span><span style="color: #CE9178">"Task generated by Debugger."</span></span> <span class="line"><span style="color: #BBBBBB"> }</span></span> <span class="line"><span style="color: #BBBBBB"> ],</span></span> <span class="line"><span style="color: #BBBBBB"> </span><span style="color: #9CDCFE">"version"</span><span style="color: #BBBBBB">: </span><span style="color: #CE9178">"2.0.0"</span></span> <span class="line"><span style="color: #BBBBBB">}</span></span> <span class="line"></span></code></pre> <blockquote><p><strong>Note</strong>: You can learn more about <code>tasks.json</code> variables in the <a href="/docs/editor/variables-reference">variables reference</a>.</p> </blockquote><p>The <code>command</code> setting specifies the program to run; in this case that is <code>g++</code>.</p> <p>The <code>args</code> array specifies the command-line arguments passed to g++. These arguments are listed in this file in the specific order expected by the compiler.</p> <p>This task tells g++ to take the active file (<code>${file}</code>), compile it, and create an output file (<code>-o</code> switch) in the current directory (<code>${fileDirname}</code>) with the same name as the active file but with the <code>.exe</code> extension (<code>${fileBasenameNoExtension}.exe</code>). For us, this results in <code>helloworld.exe</code>.</p> <p>The <code>label</code> value is what you will see in the tasks list; you can name this whatever you like.</p> <p>The <code>detail</code> value is what you will see as the description of the task in the tasks list. It's highly recommended to rename this value to differentiate it from similar tasks.</p> <p>The <code>problemMatcher</code> value selects the output parser to use for finding errors and warnings in the compiler output. For GCC, you'll get the best results if you use the <code>$gcc</code> problem matcher.</p> <p>From now on, the play button will read from <code>tasks.json</code> to figure out how to build and run your program. You can define multiple build tasks in <code>tasks.json</code>, and whichever task is marked as the default will be used by the play button. In case you need to change the default compiler, you can run <strong>Tasks: Configure Default Build Task</strong> in the Command Palette. Alternatively you can modify the <code>tasks.json</code> file and remove the default by replacing this segment:</p> <pre class="shiki" style="background-color: #1e1e1e"><code><span class="line"><span style="color: #BBBBBB"> </span><span style="color: #CE9178">"group"</span><span style="color: #BBBBBB">: {</span></span> <span class="line"><span style="color: #BBBBBB"> </span><span style="color: #9CDCFE">"kind"</span><span style="color: #BBBBBB">: </span><span style="color: #CE9178">"build"</span><span style="color: #BBBBBB">,</span></span> <span class="line"><span style="color: #BBBBBB"> </span><span style="color: #9CDCFE">"isDefault"</span><span style="color: #BBBBBB">: </span><span style="color: #569CD6">true</span></span> <span class="line"><span style="color: #BBBBBB"> },</span></span> <span class="line"></span></code></pre> <p>with this:</p> <pre class="shiki" style="background-color: #1e1e1e"><code><span class="line"><span style="color: #BBBBBB"> </span><span style="color: #CE9178">"group"</span><span style="color: #BBBBBB">: </span><span style="color: #CE9178">"build"</span><span style="color: #BBBBBB">,</span></span> <span class="line"></span></code></pre> <h3 id="_modifying-tasksjson" data-needslink="_modifying-tasksjson">Modifying tasks.json</h3> <p>You can modify your <code>tasks.json</code> to build multiple C++ files by using an argument like <code>"${workspaceFolder}/*.cpp"</code> instead of <code>"${file}"</code>.This will build all <code>.cpp</code> files in your current folder. You can also modify the output filename by replacing <code>"${fileDirname}\\${fileBasenameNoExtension}.exe"</code> with a hard-coded filename (for example <code>"${workspaceFolder}\\myProgram.exe"</code>).</p> <h2 id="_debug-helloworldcpp" data-needslink="_debug-helloworldcpp">Debug helloworld.cpp</h2> <p>To debug your code,</p> <ol> <li>Go back to <code>helloworld.cpp</code> so that it is the active file.</li> <li>Set a breakpoint by clicking on the editor margin or using F9 on the current line. <img src="/assets/docs/cpp/playbutton/cpp-breakpoint.png" alt="screenshot of breakpoint in helloworld.cpp" loading="lazy"></li> <li>From the drop-down next to the play button, select <strong>Debug C/C++ File</strong>. <img src="/assets/docs/cpp/playbutton/debug-cpp-file-play-button.png" alt="Screenshot of play button drop-down" loading="lazy"></li> <li>Choose <strong>C/C++: g++ build and debug active file</strong> from the list of detected compilers on your system (you'll only be asked to choose a compiler the first time you run or debug <code>helloworld.cpp</code>). <img src="/assets/docs/cpp/playbutton/select-gcc-compiler.png" alt="C++ debug configuration dropdown" loading="lazy"></li> </ol> <p>The play button has two modes: <strong>Run C/C++ File</strong> and <strong>Debug C/C++ File</strong>. It will default to the last-used mode. If you see the debug icon in the play button, you can just select the play button to debug, instead of using the drop-down.</p> <h2 id="_explore-the-debugger" data-needslink="_explore-the-debugger">Explore the debugger</h2> <p>Before you start stepping through the code, let's take a moment to notice several changes in the user interface:</p> <ul> <li> <p>The Integrated Terminal appears at the bottom of the source code editor. In the <strong>Debug Console</strong> tab, you see output that indicates the debugger is up and running.</p> </li> <li> <p>The editor highlights the line where you set a breakpoint before starting the debugger:</p> <p><img src="/assets/docs/cpp/playbutton/breakpoint-debug.png" alt="Initial breakpoint" loading="lazy"></p> </li> <li> <p>The <strong>Run and Debug</strong> view on the left shows debugging information. You'll see an example later in the tutorial.</p> </li> <li> <p>At the top of the code editor, a debugging control panel appears. You can move this around the screen by grabbing the dots on the left side.</p> <p><img src="/assets/docs/cpp/cpp/debug-controls.png" alt="Debugging controls" loading="lazy"></p> </li> </ul> <h3 id="_step-through-the-code" data-needslink="_step-through-the-code">Step through the code</h3> <p>Now you're ready to start stepping through the code.</p> <ol> <li> <p>Select the <strong>Step over</strong> icon in the debugging control panel.</p> <p><img src="/assets/docs/cpp/cpp/step-over-button.png" alt="Step over button" loading="lazy"></p> <p>This will advance program execution to the first line of the for loop, and skip over all the internal function calls within the <code>vector</code> and <code>string</code> classes that are invoked when the <code>msg</code> variable is created and initialized. Notice the change in the <strong>Variables</strong> window on the left.</p> <p><img src="/assets/docs/cpp/wsl/debug-view-variables.png" alt="Debugging windows" loading="lazy"></p> <p>In this case, the errors are expected because, although the variable names for the loop are now visible to the debugger, the statement has not executed yet, so there is nothing to read at this point. The contents of <code>msg</code> are visible, however, because that statement has completed.</p> </li> <li> <p>Press <strong>Step over</strong> again to advance to the next statement in this program (skipping over all the internal code that is executed to initialize the loop). Now, the <strong>Variables</strong> window shows information about the loop variables.</p> </li> <li> <p>Press <strong>Step over</strong> again to execute the <code>cout</code> statement. (Note that the C++ extension does not print any output to the <strong>Debug Console</strong> until the loop exits.)</p> </li> <li> <p>If you like, you can keep pressing <strong>Step over</strong> until all the words in the vector have been printed to the console. But if you are curious, try pressing the <strong>Step Into</strong> button to step through source code in the C++ standard library!</p> <p>To return to your own code, one way is to keep pressing <strong>Step over</strong>. Another way is to set a breakpoint in your code by switching to the <code>helloworld.cpp</code> tab in the code editor, putting the insertion point somewhere on the <code>cout</code> statement inside the loop, and pressing <span class="dynamic-keybinding" data-commandId="editor.debug.action.toggleBreakpoint" data-osx="F9" data-win="F9" data-linux="F9"><span class="keybinding">F9</span></span>. A red dot appears in the gutter on the left to indicate that a breakpoint has been set on this line.</p> <p><img src="/assets/docs/cpp/cpp/breakpoint-in-main.png" alt="Breakpoint in main" loading="lazy"></p> <p>Then press <span class="dynamic-keybinding" data-commandId="workbench.action.debug.start" data-osx="F5" data-win="F5" data-linux="F5"><span class="keybinding">F5</span></span> to start execution from the current line in the standard library header. Execution will break on <code>cout</code>. If you like, you can press <span class="dynamic-keybinding" data-commandId="editor.debug.action.toggleBreakpoint" data-osx="F9" data-win="F9" data-linux="F9"><span class="keybinding">F9</span></span> again to toggle off the breakpoint.</p> <p>When the loop has completed, you can see the output in the Integrated Terminal, along with some other diagnostic information that is output by GDB.</p> <p><img src="/assets/docs/cpp/mingw/mingw-debug-output.png" alt="Debug output in terminal" loading="lazy"></p> </li> </ol> <h3 id="_set-a-watch" data-needslink="_set-a-watch">Set a watch</h3> <p>Sometimes you might want to keep track of the value of a variable as your program executes. You can do this by setting a <strong>watch</strong> on the variable.</p> <ol> <li> <p>Place the insertion point inside the loop. In the <strong>Watch</strong> window, select the plus sign and in the text box, type <code>word</code>, which is the name of the loop variable. Now view the Watch window as you step through the loop.</p> <p><img src="/assets/docs/cpp/cpp/watch-window.png" alt="Watch window" loading="lazy"></p> </li> <li> <p>Add another watch by adding this statement before the loop: <code>int i = 0;</code>. Then, inside the loop, add this statement: <code>++i;</code>. Now add a watch for <code>i</code> as you did in the previous step.</p> </li> <li> <p>To quickly view the value of any variable while execution is paused on a breakpoint, you can hover over it with the mouse pointer.</p> <p><img src="/assets/docs/cpp/cpp/mouse-hover.png" alt="Mouse hover" loading="lazy"></p> </li> </ol> <h2 id="_customize-debugging-with-launchjson" data-needslink="_customize-debugging-with-launchjson">Customize debugging with launch.json</h2> <p>When you debug with the play button or <span class="dynamic-keybinding" data-commandId="workbench.action.debug.start" data-osx="F5" data-win="F5" data-linux="F5"><span class="keybinding">F5</span></span>, the C++ extension creates a dynamic debug configuration on the fly.</p> <p>There are cases where you'd want to customize your debug configuration, such as specifying arguments to pass to the program at runtime. You can define custom debug configurations in a <code>launch.json</code> file.</p> <p>To create <code>launch.json</code>, choose <strong>Add Debug Configuration</strong> from the play button drop-down menu.</p> <p><img src="/assets/docs/cpp/playbutton/add-debug-configuration.png" alt="Add debug configuration play button menu" loading="lazy"></p> <p>You'll then see a dropdown for various predefined debugging configurations. Choose <strong>C/C++: g++.exe build and debug active file</strong>.</p> <p><img src="/assets/docs/cpp/playbutton/select-gcc-compiler.png" alt="C++ debug configuration dropdown" loading="lazy"></p> <p>VS Code creates a <code>launch.json</code> file in the <code>.vscode</code> folder`, which looks something like this:</p> <pre class="shiki" style="background-color: #1e1e1e"><code><span class="line"><span style="color: #BBBBBB">{</span></span> <span class="line"><span style="color: #BBBBBB"> </span><span style="color: #9CDCFE">"configurations"</span><span style="color: #BBBBBB">: [</span></span> <span class="line"><span style="color: #BBBBBB"> {</span></span> <span class="line"><span style="color: #BBBBBB"> </span><span style="color: #9CDCFE">"name"</span><span style="color: #BBBBBB">: </span><span style="color: #CE9178">"C/C++: g++.exe build and debug active file"</span><span style="color: #BBBBBB">,</span></span> <span class="line"><span style="color: #BBBBBB"> </span><span style="color: #9CDCFE">"type"</span><span style="color: #BBBBBB">: </span><span style="color: #CE9178">"cppdbg"</span><span style="color: #BBBBBB">,</span></span> <span class="line"><span style="color: #BBBBBB"> </span><span style="color: #9CDCFE">"request"</span><span style="color: #BBBBBB">: </span><span style="color: #CE9178">"launch"</span><span style="color: #BBBBBB">,</span></span> <span class="line"><span style="color: #BBBBBB"> </span><span style="color: #9CDCFE">"program"</span><span style="color: #BBBBBB">: </span><span style="color: #CE9178">"${fileDirname}</span><span style="color: #D7BA7D">\\</span><span style="color: #CE9178">${fileBasenameNoExtension}.exe"</span><span style="color: #BBBBBB">,</span></span> <span class="line"><span style="color: #BBBBBB"> </span><span style="color: #9CDCFE">"args"</span><span style="color: #BBBBBB">: [],</span></span> <span class="line"><span style="color: #BBBBBB"> </span><span style="color: #9CDCFE">"stopAtEntry"</span><span style="color: #BBBBBB">: </span><span style="color: #569CD6">false</span><span style="color: #BBBBBB">,</span></span> <span class="line"><span style="color: #BBBBBB"> </span><span style="color: #9CDCFE">"cwd"</span><span style="color: #BBBBBB">: </span><span style="color: #CE9178">"${fileDirname}"</span><span style="color: #BBBBBB">,</span></span> <span class="line"><span style="color: #BBBBBB"> </span><span style="color: #9CDCFE">"environment"</span><span style="color: #BBBBBB">: [],</span></span> <span class="line"><span style="color: #BBBBBB"> </span><span style="color: #9CDCFE">"externalConsole"</span><span style="color: #BBBBBB">: </span><span style="color: #569CD6">false</span><span style="color: #BBBBBB">,</span></span> <span class="line"><span style="color: #BBBBBB"> </span><span style="color: #9CDCFE">"MIMode"</span><span style="color: #BBBBBB">: </span><span style="color: #CE9178">"gdb"</span><span style="color: #BBBBBB">,</span></span> <span class="line"><span style="color: #BBBBBB"> </span><span style="color: #9CDCFE">"miDebuggerPath"</span><span style="color: #BBBBBB">: </span><span style="color: #CE9178">"C:</span><span style="color: #D7BA7D">\\</span><span style="color: #CE9178">msys64</span><span style="color: #D7BA7D">\\</span><span style="color: #CE9178">ucrt64</span><span style="color: #D7BA7D">\\</span><span style="color: #CE9178">bin</span><span style="color: #D7BA7D">\\</span><span style="color: #CE9178">gdb.exe"</span><span style="color: #BBBBBB">,</span></span> <span class="line"><span style="color: #BBBBBB"> </span><span style="color: #9CDCFE">"setupCommands"</span><span style="color: #BBBBBB">: [</span></span> <span class="line"><span style="color: #BBBBBB"> {</span></span> <span class="line"><span style="color: #BBBBBB"> </span><span style="color: #9CDCFE">"description"</span><span style="color: #BBBBBB">: </span><span style="color: #CE9178">"Enable pretty-printing for gdb"</span><span style="color: #BBBBBB">,</span></span> <span class="line"><span style="color: #BBBBBB"> </span><span style="color: #9CDCFE">"text"</span><span style="color: #BBBBBB">: </span><span style="color: #CE9178">"-enable-pretty-printing"</span><span style="color: #BBBBBB">,</span></span> <span class="line"><span style="color: #BBBBBB"> </span><span style="color: #9CDCFE">"ignoreFailures"</span><span style="color: #BBBBBB">: </span><span style="color: #569CD6">true</span></span> <span class="line"><span style="color: #BBBBBB"> },</span></span> <span class="line"><span style="color: #BBBBBB"> {</span></span> <span class="line"><span style="color: #BBBBBB"> </span><span style="color: #9CDCFE">"description"</span><span style="color: #BBBBBB">: </span><span style="color: #CE9178">"Set Disassembly Flavor to Intel"</span><span style="color: #BBBBBB">,</span></span> <span class="line"><span style="color: #BBBBBB"> </span><span style="color: #9CDCFE">"text"</span><span style="color: #BBBBBB">: </span><span style="color: #CE9178">"-gdb-set disassembly-flavor intel"</span><span style="color: #BBBBBB">,</span></span> <span class="line"><span style="color: #BBBBBB"> </span><span style="color: #9CDCFE">"ignoreFailures"</span><span style="color: #BBBBBB">: </span><span style="color: #569CD6">true</span></span> <span class="line"><span style="color: #BBBBBB"> }</span></span> <span class="line"><span style="color: #BBBBBB"> ],</span></span> <span class="line"><span style="color: #BBBBBB"> </span><span style="color: #9CDCFE">"preLaunchTask"</span><span style="color: #BBBBBB">: </span><span style="color: #CE9178">"C/C++: g++.exe build active file"</span></span> <span class="line"><span style="color: #BBBBBB"> }</span></span> <span class="line"><span style="color: #BBBBBB"> ],</span></span> <span class="line"><span style="color: #BBBBBB"> </span><span style="color: #9CDCFE">"version"</span><span style="color: #BBBBBB">: </span><span style="color: #CE9178">"2.0.0"</span></span> <span class="line"><span style="color: #BBBBBB">}</span></span> <span class="line"></span></code></pre> <p>In the JSON above, <code>program</code> specifies the program you want to debug. Here it is set to the active file folder (<code>${fileDirname}</code>) and active filename with the <code>.exe</code> extension (<code>${fileBasenameNoExtension}.exe</code>), which if <code>helloworld.cpp</code> is the active file will be <code>helloworld.exe</code>. The <code>args</code> property is an array of arguments to pass to the program at runtime.</p> <p>By default, the C++ extension won't add any breakpoints to your source code and the <code>stopAtEntry</code> value is set to <code>false</code>.</p> <p>Change the <code>stopAtEntry</code> value to <code>true</code> to cause the debugger to stop on the <code>main</code> method when you start debugging.</p> <blockquote><p>From now on, the play button and <span class="dynamic-keybinding" data-commandId="workbench.action.debug.start" data-osx="F5" data-win="F5" data-linux="F5"><span class="keybinding">F5</span></span> will read from your <code>launch.json</code> file when launching your program for debugging.</p> </blockquote><h2 id="_adding-additional-cc-settings" data-needslink="_adding-additional-cc-settings">Adding additional C/C++ settings</h2> <p>If you want more control over the C/C++ extension, you can create a <code>c_cpp_properties.json</code> file, which will allow you to change settings such as the path to the compiler, include paths, C++ standard (default is C++17), and more.</p> <p>You can view the C/C++ configuration UI by running the command <strong>C/C++: Edit Configurations (UI)</strong> from the Command Palette (<span class="dynamic-keybinding" data-commandId="workbench.action.showCommands" data-osx="鈬р寴P" data-win="Ctrl+Shift+P" data-linux="Ctrl+Shift+P"><span class="keybinding">鈬р寴P</span> (Windows, Linux <span class="keybinding">Ctrl+Shift+P</span>)</span>).</p> <p><img src="/assets/docs/cpp/cpp/command-palette.png" alt="Command Palette" loading="lazy"></p> <p>This opens the <strong>C/C++ Configurations</strong> page. When you make changes here, VS Code writes them to a file called <code>c_cpp_properties.json</code> in the <code>.vscode</code> folder.</p> <p>Here, we've changed the <strong>Configuration name</strong> to <strong>GCC</strong>, set the <strong>Compiler path</strong> dropdown to the g++ compiler, and the <strong>IntelliSense mode</strong> to match the compiler (<strong>gcc-x64</strong>).</p> <p><img src="/assets/docs/cpp/mingw/intellisense-configurations-mingw.png" alt="Command Palette" loading="lazy"></p> <p>Visual Studio Code places these settings in <code>.vscode\c_cpp_properties.json</code>. If you open that file directly, it should look something like this:</p> <pre class="shiki" style="background-color: #1e1e1e"><code><span class="line"><span style="color: #BBBBBB">{</span></span> <span class="line"><span style="color: #BBBBBB"> </span><span style="color: #9CDCFE">"configurations"</span><span style="color: #BBBBBB">: [</span></span> <span class="line"><span style="color: #BBBBBB"> {</span></span> <span class="line"><span style="color: #BBBBBB"> </span><span style="color: #9CDCFE">"name"</span><span style="color: #BBBBBB">: </span><span style="color: #CE9178">"GCC"</span><span style="color: #BBBBBB">,</span></span> <span class="line"><span style="color: #BBBBBB"> </span><span style="color: #9CDCFE">"includePath"</span><span style="color: #BBBBBB">: [</span><span style="color: #CE9178">"${workspaceFolder}/**"</span><span style="color: #BBBBBB">],</span></span> <span class="line"><span style="color: #BBBBBB"> </span><span style="color: #9CDCFE">"defines"</span><span style="color: #BBBBBB">: [</span><span style="color: #CE9178">"_DEBUG"</span><span style="color: #BBBBBB">, </span><span style="color: #CE9178">"UNICODE"</span><span style="color: #BBBBBB">, </span><span style="color: #CE9178">"_UNICODE"</span><span style="color: #BBBBBB">],</span></span> <span class="line"><span style="color: #BBBBBB"> </span><span style="color: #9CDCFE">"windowsSdkVersion"</span><span style="color: #BBBBBB">: </span><span style="color: #CE9178">"10.0.22000.0"</span><span style="color: #BBBBBB">,</span></span> <span class="line"><span style="color: #BBBBBB"> </span><span style="color: #9CDCFE">"compilerPath"</span><span style="color: #BBBBBB">: </span><span style="color: #CE9178">"C:/msys64/mingw64/bin/g++.exe"</span><span style="color: #BBBBBB">,</span></span> <span class="line"><span style="color: #BBBBBB"> </span><span style="color: #9CDCFE">"cStandard"</span><span style="color: #BBBBBB">: </span><span style="color: #CE9178">"c17"</span><span style="color: #BBBBBB">,</span></span> <span class="line"><span style="color: #BBBBBB"> </span><span style="color: #9CDCFE">"cppStandard"</span><span style="color: #BBBBBB">: </span><span style="color: #CE9178">"c++17"</span><span style="color: #BBBBBB">,</span></span> <span class="line"><span style="color: #BBBBBB"> </span><span style="color: #9CDCFE">"intelliSenseMode"</span><span style="color: #BBBBBB">: </span><span style="color: #CE9178">"windows-gcc-x64"</span></span> <span class="line"><span style="color: #BBBBBB"> }</span></span> <span class="line"><span style="color: #BBBBBB"> ],</span></span> <span class="line"><span style="color: #BBBBBB"> </span><span style="color: #9CDCFE">"version"</span><span style="color: #BBBBBB">: </span><span style="color: #B5CEA8">4</span></span> <span class="line"><span style="color: #BBBBBB">}</span></span> <span class="line"></span></code></pre> <p>You only need to add to the <strong>Include path</strong> array setting if your program includes header files that are not in your workspace or in the standard library path.</p> <h3 id="_compiler-path" data-needslink="_compiler-path">Compiler path</h3> <p>The extension uses the <code>compilerPath</code> setting to infer the path to the C++ standard library header files. When the extension knows where to find those files, it can provide features like smart completions and <strong>Go to Definition</strong> navigation.</p> <p>The C/C++ extension attempts to populate <code>compilerPath</code> with the default compiler location based on what it finds on your system. The extension looks in several common compiler locations.</p> <p>The <code>compilerPath</code> search order is:</p> <ul> <li>First check for the Microsoft Visual C++ compiler</li> <li>Then look for g++ on Windows Subsystem for Linux (WSL)</li> <li>Then g++ for MinGW-w64.</li> </ul> <p>If you have Visual Studio or WSL installed, you might need to change <code>compilerPath</code> to match the preferred compiler for your project. For example, if you installed MinGW-w64 version 8.1.0 using the i686 architecture, Win32 threading, and sjlj exception handling install options, the path would look like this: <code>C:\Program Files (x86)\mingw-w64\i686-8.1.0-win32-sjlj-rt_v6-rev0\mingw64\bin\g++.exe</code>.</p> <h2 id="_troubleshooting" data-needslink="_troubleshooting">Troubleshooting</h2> <h3 id="_msys2-is-installed-but-g-and-gdb-are-still-not-found" data-needslink="_msys2-is-installed-but-g-and-gdb-are-still-not-found">MSYS2 is installed, but g++ and gdb are still not found</h3> <p>You must follow the steps on the <a href="https://www.msys2.org/" class="external-link" target="_blank">MSYS2 website</a> to use the MSYS CLI to install the full MinGW-w64 toolchain(<code>pacman -S --needed base-devel mingw-w64-ucrt-x86_64-toolchain</code>), as well as all required prerequisites. The toolchain includes g++ and gdb.</p> <h3 id="_as-a-windows-user-running-the-pacman-command-gives-me-an-error" data-needslink="_as-a-windows-user-running-the-pacman-command-gives-me-an-error">As a Windows user, running the pacman command gives me an error</h3> <p>UCRT on Windows machines is only included in Windows 10 or later. If you are using another version of Windows, run the following command that does not use UCRT:</p> <pre><code class="MSYS2">pacman -S --needed base-devel mingw-w64-x86_64-toolchain </code></pre> <p>When adding the the MinGW-w64 destination folder to your list of environment variables, the default path will then be: <code>C:\msys64\mingw64\bin</code>.</p> <h3 id="_mingw-32bit" data-needslink="_mingw-32bit">MinGW 32-bit</h3> <p>If you need a 32-bit version of the MinGW toolset, consult the <a href="https://www.msys2.org/wiki/MSYS2-installation/" class="external-link" target="_blank">Downloading</a> section on the MSYS2 wiki. It includes links to both 32-bit and 64-bit installation options.</p> <h2 id="_next-steps" data-needslink="_next-steps">Next steps</h2> <ul> <li>Explore the <a href="/docs/editor/codebasics">VS Code User Guide</a>.</li> <li>Review the <a href="/docs/languages/cpp">Overview of the C++ extension</a>.</li> <li>Create a new workspace, copy your <code>.vscode</code> JSON files to it, adjust the necessary settings for the new workspace path, program name, etc. and start coding!</li> </ul> <div class="feedback"></div> <div class="body-footer">12/14/2023</div> </main> <!-- medium right nav --> <div class="col-sm-3 col-md-2 hidden-xs docs-subnavbar-container"> <nav id="docs-subnavbar" aria-label="On Page" data-spy="affix" data-offset-top="20"> <h4><span class="sr-only">In this article there are 11 sections</span><span aria-hidden="true">In this article</span></h4> <ul class="nav"> <li><a href="#_prerequisites">Prerequisites</a></li> <li><a href="#_installing-the-mingww64-toolchain">Installing the MinGW-w64 toolchain</a></li> <li><a href="#_create-a-hello-world-app">Create a Hello World app</a></li> <li><a href="#_explore-intellisense">Explore IntelliSense</a></li> <li><a href="#_run-helloworldcpp">Run helloworld.cpp</a></li> <li><a href="#_debug-helloworldcpp">Debug helloworld.cpp</a></li> <li><a href="#_explore-the-debugger">Explore the debugger</a></li> <li><a href="#_customize-debugging-with-launchjson">Customize debugging with launch.json</a></li> <li><a href="#_adding-additional-cc-settings">Adding additional C/C++ settings</a></li> <li><a href="#_troubleshooting">Troubleshooting</a></li> <li><a href="#_next-steps">Next steps</a></li> </ul> <div class="connect-widget"></div> </nav> </div> <!-- end of page connect widget --> <div class="col-xs-12 visible-xs"> <div class="connect-widget"></div> </div> </div> </div> </div> </div> <footer role="contentinfo" class="container"> <div class="footer-container"> <div class="footer-row"> <div class="footer-social"> <ul class="links"> <li> <a href="https://go.microsoft.com/fwlink/?LinkID=533687"><img src="/assets/icons/x-icon.svg" class="x-icon" alt="Follow us on X"></a> </li> <li> <a href="https://github.com/microsoft/vscode"><img src="/assets/icons/github-icon.svg" alt="VS Code on Github"></a> </li> <li> <a href="https://www.youtube.com/@code"><img src="/assets/icons/youtube-icon.svg" alt="VS Code on YouTube"></a> </li> <script> function manageConsent() { if (siteConsent && siteConsent.isConsentRequired) { siteConsent.manageConsent(); } } </script> </ul> <a id="footer-microsoft-link" class="microsoft-logo" href="https://www.microsoft.com"> <img src="/assets/icons/microsoft.svg" alt="Microsoft homepage" /> </a> </div> </div> <div class="footer-row"> <ul class="links"> <li><a id="footer-support-link" href="https://support.serviceshub.microsoft.com/supportforbusiness/create?sapId=d66407ed-3967-b000-4cfb-2c318cad363d" target="_blank" rel="noopener">Support</a></li> <li><a id="footer-privacy-link" href="https://go.microsoft.com/fwlink/?LinkId=521839" target="_blank" rel="noopener">Privacy</a></li> <li style="display: none;"><a id="footer-cookie-link" style="cursor: pointer;" onclick="manageConsent()" target="_blank" rel="noopener">Manage Cookies</a></li> <li><a id="footer-terms-link" href="https://www.microsoft.com/legal/terms-of-use" target="_blank" rel="noopener">Terms of Use</a></li> <li><a id="footer-license-link" href="/License" target="_blank" rel="noopener">License</a></li> </ul> </div> </div> </footer> <script src="/dist/index.js"></script> <script type="application/ld+json"> { "@context" : "http://schema.org", "@type" : "SoftwareApplication", "name" : "Visual Studio Code", "softwareVersion": "1.95", "offers": { "@type": "Offer", "price": "0", "priceCurrency": "USD" }, "applicationCategory": "DeveloperApplication", "applicationSubCategory": "Text Editor", "alternateName": "VS Code", "datePublished": "2021-11-03", "operatingSystem": "Mac, Linux, Windows", "logo": "https://code.visualstudio.com/assets/apple-touch-icon.png", "screenshot": "https://code.visualstudio.com/assets/home/home-screenshot-win.png", "releaseNotes": "https://code.visualstudio.com/updates", "downloadUrl": "https://code.visualstudio.com/download", "license": "https://code.visualstudio.com/license", "softwareRequirements": "https://code.visualstudio.com/docs/supporting/requirements", "url" : "https://code.visualstudio.com", "author": { "@type": "Organization", "name": "Microsoft" }, "publisher": { "@type": "Organization", "name": "Microsoft" }, "maintainer": { "@type": "Organization", "name": "Microsoft" }, "potentialAction": { "@type": "SearchAction", "target": "https://code.visualstudio.com/Search?q={search_term_string}", "query-input": "required name=search_term_string" }, "sameAs" : [ "https://en.wikipedia.org/wiki/Visual_Studio_Code", "https://twitter.com/code", "https://www.youtube.com/code", "https://www.tiktok.com/@vscode", "https://github.com/microsoft/vscode" ] } </script> </body> </html>