From dfeb7bbfbd0f5236872c6c1dd3dfcbb788659084 Mon Sep 17 00:00:00 2001 From: alkemper_microsoft Date: Fri, 14 Jul 2023 16:36:18 -0700 Subject: [PATCH 1/6] Freshness pass on Mingw on Windows --- docs/cpp/config-mingw.md | 160 +++++++++++------- docs/cpp/images/cpp/cpp-extension.png | 4 +- .../cpp/cpp-install-MSYS2-toolchain.png | 3 + docs/cpp/images/playbutton/debug-button.png | 3 - .../playbutton/debug-cpp-file-play-button.png | 4 +- .../cpp/images/playbutton/run-debug-arrow.png | 3 - .../cpp/images/playbutton/run-play-button.png | 4 +- 7 files changed, 104 insertions(+), 77 deletions(-) create mode 100644 docs/cpp/images/cpp/cpp-install-MSYS2-toolchain.png delete mode 100644 docs/cpp/images/playbutton/debug-button.png delete mode 100644 docs/cpp/images/playbutton/run-debug-arrow.png diff --git a/docs/cpp/config-mingw.md b/docs/cpp/config-mingw.md index 6b331f8921..59499dcf36 100644 --- a/docs/cpp/config-mingw.md +++ b/docs/cpp/config-mingw.md @@ -3,17 +3,17 @@ Order: 3 Area: cpp TOCTitle: GCC on Windows ContentId: 7efec972-6556-4526-8aa8-c73b3319d612 -PageTitle: Get Started with C++ and Mingw-w64 in Visual Studio Code -DateApproved: 5/13/2022 -MetaDescription: Configuring the C++ extension in Visual Studio Code to target g++ and gdb on a Mingw-w64 installation +PageTitle: Get Started with C++ and MinGW-w64 in Visual Studio Code +DateApproved: 7/14/2023 +MetaDescription: Configuring the C++ extension in Visual Studio Code to target g++ and gdb on a MinGW-w64 installation --- # Using GCC with MinGW -In this tutorial, you configure Visual Studio Code to use the GCC C++ compiler (g++) and GDB debugger from [mingw-w64](http://mingw-w64.org) to create programs that run on Windows. +In this tutorial, you configure Visual Studio Code to use the GCC C++ compiler (g++) and GDB debugger from [mingw-w64](http://mingw-w64.org) to create programs that run on Windows. After configuring VS Code, you will compile, run, and debug a simple Hello World program. -After configuring VS Code, you will compile and debug a simple Hello World program in VS Code. 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. +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. -If you have any problems, feel free to file an issue for this tutorial in the [VS Code documentation repository](https://github.com/microsoft/vscode-docs/issues). +If you have any problems, feel free to file an issue for this tutorial in the [VS Code documentation repository](https://github.com/microsoft/vscode-docs/issues/new). ## Prerequisites @@ -21,40 +21,58 @@ To successfully complete this tutorial, you must do the following steps: 1. Install [Visual Studio Code](/download). -1. Install the [C/C++ extension for VS Code](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools). You can install the C/C++ extension by searching for 'c++' in the Extensions view (`kb(workbench.view.extensions)`). +1. Install the [C/C++ extension for VS Code](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools). You can install the C/C++ extension by searching for 'C++' in the Extensions view (`kb(workbench.view.extensions)`). ![C/C++ extension](images/cpp/cpp-extension.png) -1. Get the latest version of Mingw-w64 via [MSYS2](https://www.msys2.org/), which provides up-to-date native builds of GCC, Mingw-w64, and other helpful C++ tools and libraries. You can download the latest installer from the MSYS2 page or use this [link to the installer](https://github.com/msys2/msys2-installer/releases/download/2022-06-03/msys2-x86_64-20220603.exe). +## Installing the MinGW-w64 toolchain +Get the latest version of MinGW-w64 via [MSYS2](https://www.msys2.org/), 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 [IntelliSense](/editor/intellisense). -1. Follow the **Installation** instructions on the [MSYS2 website](https://www.msys2.org/) to install Mingw-w64. Take care to run each required Start menu and `pacman` command. +You can download the latest installer from the MSYS2 page or use this [**direct link to the installer**](https://github.com/msys2/msys2-installer/releases/download/2023-05-26/msys2-x86_64-20230526.exe). -1. Install the Mingw-w64 toolchain (`pacman -S --needed base-devel mingw-w64-x86_64-toolchain`). Run the `pacman` command in a MSYS2 terminal. Accept the default to install all the members in the `toolchain` group. +1. Run the installer and follow the steps of the installation wizard. Note that MSYS2 requires 64 bit Windows 8.1 or newer. -1. Add the path to your Mingw-w64 `bin` folder to the Windows `PATH` environment variable by using the following steps: - 1. In the Windows search bar, type 'settings' to open your Windows Settings. +1. 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 "Run MSYS2 now" box is checked and click "Finish". This will open a MSYS2 terminal window for you. + +1. In this terminal, install the MinGW-w64 toolchain by running the following command. +```MSYS2 +pacman -S --needed base-devel mingw-w64-x86_64-toolchain +``` + + +1. Accept the default number of packages in the `toolchain` troup by pressing the `Enter` key. + + ![MYSS2 Installer](images/cpp/cpp-install-MSYS2-toolchain.png) + +1. Enter `Y` when prompted whether to proceed with the installation. + +1. Add the path to your MinGW-w64 `bin` folder to the Windows `PATH` environment variable by using the following steps: + 1. In the Windows search bar, type **Settings** to open your Windows Settings. 1. Search for **Edit environment variables for your account**. - 1. Choose the `Path` variable in your **User variables** and then select **Edit**. - 1. Select **New** and add the Mingw-w64 destination folder path to the system path. The exact path depends on which version of Mingw-w64 you have installed and where you installed it. If you used the settings above to install Mingw-w64, then add this to the path: `C:\msys64\mingw64\bin`. + 1. In your **User variables**, select the `Path` variable and then select **Edit**. + 1. Select **New** 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: `C:\msys64\mingw64\bin`. 1. Select **OK** to save the updated PATH. You will need to reopen any console windows for the new PATH location to be available. ### Check your MinGW installation -To check that your Mingw-w64 tools are correctly installed and available, open a **new** Command Prompt and type: +To check that your MinGW-w64 tools are correctly installed and available, open a **new** Command Prompt and type: ```bash gcc --version g++ --version gdb --version ``` +You should see output that states which versions of GCC, g++ and GDB you have installed. If this is not the case: +1. Make sure your PATH variable entry matches the MinGW-w64 binary location where the toochain was installed. If the compilers do not exist at that PATH entry, make sure you followed the previous instructions. +2. If `gcc` has the correct output but not `gdb`, then you need to install the packages you are missing from the MinGW-w64 toolset. + - If on compilation your are getting the "The value of miDebuggerPath is invalid." message, one cause can be you are missing the `mingw-w64-gdb` package. -1. If you don't see the expected output or `g++` or `gdb` is not a recognized command, make sure your PATH entry matches the Mingw-w64 binary location where the compilers are located. If the compilers do not exist at that PATH entry, make sure you followed the instructions on the [MSYS2 website](https://www.msys2.org/) to install Mingw-w64. -2. If `gcc` has the correct output but not `gdb`, then you need to install the packages you are missing from the Mingw-w64 toolset. - - Missing the `mingw-w64-gdb` package is one cause of the "The value of miDebuggerPath is invalid." message upon attempted compilation if your PATH is correct. +## Create A Hello World App -## Create Hello World +First, lets get a project set up. -From a Windows command prompt, create an empty folder called `projects` where you can place all your VS Code projects. Then create a sub-folder called `helloworld`, navigate into it, and open VS Code in that folder by entering the following commands: +1. Launch a Windows command prompt (Enter **Windows command prompt** in the Windows search bar), then +1. Run the following commands. These will create an empty folder called `projects` where you can place all your VS Code projects. There, the next commands will create and navigate to a sub-folder called `helloworld`. From there, you will open `helloworld` directly in VS Code. ```bat mkdir projects @@ -105,23 +123,26 @@ Now press `kb(workbench.action.files.save)` to save the file. Notice how the fil ![File Explorer](images/mingw/file-explorer-mingw.png) -You can also enable [Auto Save](/docs/editor/codebasics.md#save-auto-save) to automatically save your file changes, by checking **Auto Save** in the main **File** menu. - -The Activity Bar on the far left lets you open different views such as **Search**, **Source Control**, and **Run**. You'll look at the **Run** view later in this tutorial. You can find out more about the other views in the VS Code [User Interface documentation](/docs/getstarted/userinterface.md). +You can also enable [Auto Save](/docs/editor/codebasics.md#save-auto-save) to automatically save your file changes, by selecting **File** > **Auto Save**. You can find out more about the other views in the VS Code [User Interface documentation](/docs/getstarted/userinterface.md). >**Note**: 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 `X` (**Clear Notification**). ## Explore IntelliSense -In your new `helloworld.cpp` file, hover over `vector` or `string` to see type information. After the declaration of the `msg` variable, start typing `msg.` as you would when calling a member function. You should immediately see a completion list that shows all the member functions, and a window that shows the type information for the `msg` object: +[IntelliSense](/editor/intellisense) is a tool to help you code faster and more efficently by adding code editing features such as code completion, parameter info, quick info, and member lists. + +To see IntelliSense in action, +hover over `vector` or `string` to see their type information. If you type `msg.` in line 10, you can see a completion list of recommended member functions to call, all generated by IntelliSense: ![Statement completion IntelliSense](images/wsl/msg-intellisense.png) -You can press the `kbstyle(Tab)` key to insert the selected member; then, when you add the opening parenthesis, you will see information about any arguments that the function requires. +You can press the `kbstyle(Tab)` key to insert a selected member. If you then add open parenthesis, IntelliSense will show information on which arguments are required. + +If IntelliSense is not already configured, open the command palette (`kb(workbench.action.showCommands)`) and enter **Select IntelliSense Configuration**. From the dropdown of compilers, select `Use gcc.exe` to configure. ## Run helloworld.cpp -Remember, the C++ extension uses the C++ compiler you have installed on your machine to build your program. Make sure you have a C++ compiler installed before attempting to run and debug `helloworld.cpp` in VS Code. +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 `helloworld.cpp` in VS Code. 1. Open `helloworld.cpp` so that it is the active file. 2. Press the play button in the top right corner of the editor. @@ -138,7 +159,11 @@ You'll only be asked to choose a compiler the first time you run `helloworld.cpp ![screenshot of program output](images/playbutton/helloworld-terminal-output.png) -The first time you run your program, the C++ extension creates `tasks.json`, which you'll find in your project's `.vscode` folder. `tasks.json` stores build configurations. +Congradulations! You've just run your first C++ program in VS Code! + +### Understanding tasks.json + +The first time you run your program, the C++ extension creates a `tasks.json` file, which you'll find in your project's `.vscode` folder. `tasks.json` stores your build configurations. Your new `tasks.json` file should look similar to the JSON below: @@ -176,15 +201,15 @@ Your new `tasks.json` file should look similar to the JSON below: >**Note**: You can learn more about `tasks.json` variables in the [variables reference](/docs/editor/variables-reference.md). The `command` setting specifies the program to run; in this case that is g++. -The `args` array specifies the command-line arguments that will be passed to g++. These arguments must be specified in the order expected by the compiler. +The `args` array specifies the command-line arguments that will be passed to g++. These arguments are listed in this file in the specific order expected by the compiler. -This task tells g++ to take the active file (`${file}`), compile it, and create an executable file in the current directory (`${fileDirname}`) with the same name as the active file but with the `.exe` extension (`${fileBasenameNoExtension}.exe`), resulting in `helloworld.exe` for our example. +This task tells g++ to take the active file (`${file}`), compile it, and create an executable file in the current directory (`${fileDirname}`) with the same name as the active file but with the `.exe` extension (`${fileBasenameNoExtension}.exe`). For us, this results in `helloworld.exe`. The `label` value is what you will see in the tasks list; you can name this whatever you like. The `detail` value is what you will as the description of the task in the tasks list. It's highly recommended to rename this value to differentiate it from similar tasks. -From now on, the play button will read from `tasks.json` to figure out how to build and run your program. You can define multiple build tasks in `tasks.json`, 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 **Tasks: Configure default build task**. Alternatively you can modify the `tasks.json` file and remove the default by replacing this segment: +From now on, the play button will read from `tasks.json` to figure out how to build and run your program. You can define multiple build tasks in `tasks.json`, 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 **Tasks: Configure Default Build Task** in the command palette. Alternatively you can modify the `tasks.json` file and remove the default by replacing this segment: ```json "group": { @@ -205,18 +230,19 @@ You can modify your `tasks.json` to build multiple C++ files by using an argumen ## Debug helloworld.cpp +To debug your code, + 1. Go back to `helloworld.cpp` so that it is the active file. 2. Set a breakpoint by clicking on the editor margin or using F9 on the current line. ![screenshot of breakpoint in helloworld.cpp](images/playbutton/cpp-breakpoint.png) 3. From the drop-down next to the play button, select **Debug C/C++ File**. - ![Screenshot of play button drop-down](images/playbutton/run-debug-arrow.png) + ![Screenshot of play button drop-down](images/playbutton/debug-cpp-file-play-button.png) -4. Choose **C/C++: g++ build and debug active file** from the list of detected compilers on your system (you'll only be asked to choose a compiler the first time you run/debug `helloworld.cpp`). +4. Choose **C/C++: g++ build and debug active file** 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 `helloworld.cpp`). ![C++ debug configuration dropdown](images/playbutton/select-gcc-compiler.png) The play button has two modes: **Run C/C++ File** and **Debug C/C++ File**. It will default to the last-used mode. If you see the debug icon in the play button, you can just click the play button to debug, instead of using the drop-down. - ![screenshot of play button in debug mode](images/playbutton/debug-button.png) ## Explore the debugger @@ -233,7 +259,7 @@ Before you start stepping through the code, let's take a moment to notice severa ![Debugging controls](images/cpp/debug-controls.png) -## Step through the code +### Step through the code Now you're ready to start stepping through the code. @@ -263,7 +289,7 @@ Now you're ready to start stepping through the code. ![Debug output in terminal](images/mingw/mingw-debug-output.png) -## Set a watch +### Set a watch Sometimes you might want to keep track of the value of a variable as your program executes. You can do this by setting a **watch** on the variable. @@ -291,34 +317,38 @@ You'll then see a dropdown for various predefined debugging configurations. Choo ![C++ debug configuration dropdown](images/playbutton/select-gcc-compiler.png) -VS Code creates a `launch.json` file, which looks something like this: - +VS Code creates a `launch.json` file in the `.vscode` folder`, which looks something like this: ```json { - "version": "0.2.0", - "configurations": [ - { - "name": "C/C++: g++.exe build and debug active file", - "type": "cppdbg", - "request": "launch", - "program": "${fileDirname}\\${fileBasenameNoExtension}.exe", - "args": [], - "stopAtEntry": false, - "cwd": "${fileDirname}", - "environment": [], - "externalConsole": false, - "MIMode": "gdb", - "miDebuggerPath": "C:\\msys64\\mingw64\\bin\\gdb.exe", - "setupCommands": [ + "configurations": [ { - "description": "Enable pretty-printing for gdb", - "text": "-enable-pretty-printing", - "ignoreFailures": true + "name": "C/C++: g++.exe build and debug active file", + "type": "cppdbg", + "request": "launch", + "program": "${fileDirname}\\${fileBasenameNoExtension}.exe", + "args": [], + "stopAtEntry": false, + "cwd": "${fileDirname}", + "environment": [], + "externalConsole": false, + "MIMode": "gdb", + "miDebuggerPath": "C:\\msys64\\mingw64\\bin\\gdb.exe", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + }, + { + "description": "Set Disassembly Flavor to Intel", + "text": "-gdb-set disassembly-flavor intel", + "ignoreFailures": true + } + ], + "preLaunchTask": "C/C++: g++.exe build active file" } - ], - "preLaunchTask": "C/C++: g++.exe build active file" - } - ] + ], + "version": "2.0.0" } ``` @@ -330,7 +360,7 @@ Change the `stopAtEntry` value to `true` to cause the debugger to stop on the `m > From now on, the play button and `kb(workbench.action.debug.start)` will read from your `launch.json` file when launching your program for debugging. -## C/C++ configurations +## Adding additional C/C++ settings If you want more control over the C/C++ extension, you can create a `c_cpp_properties.json` 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. @@ -359,7 +389,7 @@ Visual Studio Code places these settings in `.vscode\c_cpp_properties.json`. If "UNICODE", "_UNICODE" ], - "windowsSdkVersion": "10.0.18362.0", + "windowsSdkVersion": "10.0.22000.0", "compilerPath": "C:/msys64/mingw64/bin/g++.exe", "cStandard": "c17", "cppStandard": "c++17", @@ -382,15 +412,15 @@ The `compilerPath` search order is: - First check for the Microsoft Visual C++ compiler - Then look for g++ on Windows Subsystem for Linux (WSL) -- Then g++ for Mingw-w64. +- Then g++ for MinGW-w64. -If you have Visual Studio or WSL installed, you may need to change `compilerPath` 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: `C:\Program Files (x86)\mingw-w64\i686-8.1.0-win32-sjlj-rt_v6-rev0\mingw64\bin\g++.exe`. +If you have Visual Studio or WSL installed, you may need to change `compilerPath` 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: `C:\Program Files (x86)\mingw-w64\i686-8.1.0-win32-sjlj-rt_v6-rev0\mingw64\bin\g++.exe`. ## Troubleshooting ### MSYS2 is installed, but g++ and gdb are still not found -You must follow the steps on the [MSYS2 website](https://www.msys2.org/) and use the MSYS CLI to install Mingw-w64, which contains those tools. You will also need to install the full Mingw-w64 toolchain (`pacman -S --needed base-devel mingw-w64-x86_64-toolchain`) to get the `gdb` debugger. +You must follow the steps on the [MSYS2 website](https://www.msys2.org/) and use the MSYS CLI to install MinGW-w64, which contains those tools. You will also need to install the full MinGW-w64 toolchain (`pacman -S --needed base-devel mingw-w64-x86_64-toolchain`) to get the `gdb` debugger. ### MinGW 32-bit @@ -400,4 +430,4 @@ If you need a 32-bit version of the MinGW toolset, consult the [Downloading](htt - Explore the [VS Code User Guide](/docs/editor/codebasics.md). - Review the [Overview of the C++ extension](/docs/languages/cpp.md). -- Create a new workspace, copy your `.vscode` JSON files to it, adjust the necessary settings for the new workspace path, program name, and so on, and start coding! +- Create a new workspace, copy your `.vscode` JSON files to it, adjust the necessary settings for the new workspace path, program name, etc. and start coding! diff --git a/docs/cpp/images/cpp/cpp-extension.png b/docs/cpp/images/cpp/cpp-extension.png index dd1ab40b62..1972be5585 100644 --- a/docs/cpp/images/cpp/cpp-extension.png +++ b/docs/cpp/images/cpp/cpp-extension.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:5d5d10e3d0596cc4f25b4591bdb0ba44385a5eacdb5650b91ecf38f164758664 -size 35557 +oid sha256:0116a2afb1a69984cc0b1eaf2998783c2e372d068fec54e8b4c385daaa8f806d +size 725215 diff --git a/docs/cpp/images/cpp/cpp-install-MSYS2-toolchain.png b/docs/cpp/images/cpp/cpp-install-MSYS2-toolchain.png new file mode 100644 index 0000000000..899f56335c --- /dev/null +++ b/docs/cpp/images/cpp/cpp-install-MSYS2-toolchain.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4b2361c282d727daa003553136d28c1b5eff59ca944a55a6b3808d84d9af1821 +size 599395 diff --git a/docs/cpp/images/playbutton/debug-button.png b/docs/cpp/images/playbutton/debug-button.png deleted file mode 100644 index 33b7da2203..0000000000 --- a/docs/cpp/images/playbutton/debug-button.png +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:8d6b1fa0898f360968a4a2cbedffe56177841abc4399fef9f6c94fe3ac928a9a -size 3147 diff --git a/docs/cpp/images/playbutton/debug-cpp-file-play-button.png b/docs/cpp/images/playbutton/debug-cpp-file-play-button.png index 532be0091f..ed9ea6a754 100644 --- a/docs/cpp/images/playbutton/debug-cpp-file-play-button.png +++ b/docs/cpp/images/playbutton/debug-cpp-file-play-button.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:7c6858cff4a7500f319432192c49efc8654b6ed942999feb29642dea5c73b378 -size 14878 +oid sha256:0935d55813b59e63dd0195e72a14ca3f2219e8229638ceb888789eb5ee1f1d1b +size 549038 diff --git a/docs/cpp/images/playbutton/run-debug-arrow.png b/docs/cpp/images/playbutton/run-debug-arrow.png deleted file mode 100644 index a8c7711ec0..0000000000 --- a/docs/cpp/images/playbutton/run-debug-arrow.png +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:7cb3c44fce4151f184fc1f7de187f42a5cdbc06f40629f262b128f9c4ac5337e -size 152094 diff --git a/docs/cpp/images/playbutton/run-play-button.png b/docs/cpp/images/playbutton/run-play-button.png index 9bad05071c..bbc9091813 100644 --- a/docs/cpp/images/playbutton/run-play-button.png +++ b/docs/cpp/images/playbutton/run-play-button.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:1ec50933b7b1fa4b0e0027ec5d862f87e83ca1e471d0951ee8e340291eed4678 -size 220855 +oid sha256:616314bc7a42cacc48aff20ec978bcad1f1cf9a68939d741f5dd300579067299 +size 890257 From c62921effb4a5df35a396a07cbf6afe44848d21d Mon Sep 17 00:00:00 2001 From: alkemper_microsoft Date: Mon, 17 Jul 2023 13:28:47 -0700 Subject: [PATCH 2/6] Adding UCRT --- docs/cpp/config-mingw.md | 20 ++++++++++++++----- .../cpp/cpp-install-MSYS2-toolchain.png | 4 ++-- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/docs/cpp/config-mingw.md b/docs/cpp/config-mingw.md index 59499dcf36..6634780395 100644 --- a/docs/cpp/config-mingw.md +++ b/docs/cpp/config-mingw.md @@ -36,7 +36,7 @@ You can download the latest installer from the MSYS2 page or use this [**direct 1. In this terminal, install the MinGW-w64 toolchain by running the following command. ```MSYS2 -pacman -S --needed base-devel mingw-w64-x86_64-toolchain +pacman -S --needed base-devel mingw-w64-ucrt-x86_64-toolchain ``` @@ -50,7 +50,7 @@ pacman -S --needed base-devel mingw-w64-x86_64-toolchain 1. In the Windows search bar, type **Settings** to open your Windows Settings. 1. Search for **Edit environment variables for your account**. 1. In your **User variables**, select the `Path` variable and then select **Edit**. - 1. Select **New** 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: `C:\msys64\mingw64\bin`. + 1. Select **New** 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: `C:\msys64\ucrt64\bin`. 1. Select **OK** to save the updated PATH. You will need to reopen any console windows for the new PATH location to be available. ### Check your MinGW installation @@ -159,7 +159,7 @@ You'll only be asked to choose a compiler the first time you run `helloworld.cpp ![screenshot of program output](images/playbutton/helloworld-terminal-output.png) -Congradulations! You've just run your first C++ program in VS Code! +Congratulations! You've just run your first C++ program in VS Code! ### Understanding tasks.json @@ -173,7 +173,7 @@ Your new `tasks.json` file should look similar to the JSON below: { "type": "cppbuild", "label": "C/C++: g++.exe build active file", - "command": "C:\\msys64\\mingw64\\bin\\g++.exe", + "command": "C:\\msys64\\ucrt64\\bin\\g++.exe", "args": [ "-fdiagnostics-color=always", "-g", @@ -332,7 +332,7 @@ VS Code creates a `launch.json` file in the `.vscode` folder`, which looks somet "environment": [], "externalConsole": false, "MIMode": "gdb", - "miDebuggerPath": "C:\\msys64\\mingw64\\bin\\gdb.exe", + "miDebuggerPath": "C:\\msys64\\ucrt64\\bin\\gdb.exe", "setupCommands": [ { "description": "Enable pretty-printing for gdb", @@ -422,6 +422,16 @@ If you have Visual Studio or WSL installed, you may need to change `compilerPath You must follow the steps on the [MSYS2 website](https://www.msys2.org/) and use the MSYS CLI to install MinGW-w64, which contains those tools. You will also need to install the full MinGW-w64 toolchain (`pacman -S --needed base-devel mingw-w64-x86_64-toolchain`) to get the `gdb` debugger. +### As a Windows user, running the pacman command gives me an error + +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: + +```MSYS2 +pacman -S --needed base-devel mingw-w64-x86_64-toolchain +``` + +When adding the the MinGW-w64 destination folder to your list of environment variables, the default path will then be: `C:\msys64\mingw64\bin`. + ### MinGW 32-bit If you need a 32-bit version of the MinGW toolset, consult the [Downloading](https://www.msys2.org/wiki/MSYS2-installation/) section on the MSYS2 wiki. It includes links to both 32-bit and 64-bit installation options. diff --git a/docs/cpp/images/cpp/cpp-install-MSYS2-toolchain.png b/docs/cpp/images/cpp/cpp-install-MSYS2-toolchain.png index 899f56335c..9bbf4d4e20 100644 --- a/docs/cpp/images/cpp/cpp-install-MSYS2-toolchain.png +++ b/docs/cpp/images/cpp/cpp-install-MSYS2-toolchain.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:4b2361c282d727daa003553136d28c1b5eff59ca944a55a6b3808d84d9af1821 -size 599395 +oid sha256:e8267d9937b0e24db71cb4c5e261c322cd2d9b02d7ea39bf1c85d0be462aa771 +size 721766 From 21b83aa9e75910caeb021dfb6f12df9590305861 Mon Sep 17 00:00:00 2001 From: alkemper_microsoft Date: Mon, 17 Jul 2023 13:36:41 -0700 Subject: [PATCH 3/6] Style fixes based on feedback --- docs/cpp/config-mingw.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/cpp/config-mingw.md b/docs/cpp/config-mingw.md index 6634780395..1e3278f9fb 100644 --- a/docs/cpp/config-mingw.md +++ b/docs/cpp/config-mingw.md @@ -26,13 +26,13 @@ To successfully complete this tutorial, you must do the following steps: ![C/C++ extension](images/cpp/cpp-extension.png) ## Installing the MinGW-w64 toolchain -Get the latest version of MinGW-w64 via [MSYS2](https://www.msys2.org/), 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 [IntelliSense](/editor/intellisense). +Get the latest version of MinGW-w64 via [MSYS2](https://www.msys2.org/), 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 [IntelliSense](/docs/editor/intellisense.md). You can download the latest installer from the MSYS2 page or use this [**direct link to the installer**](https://github.com/msys2/msys2-installer/releases/download/2023-05-26/msys2-x86_64-20230526.exe). 1. Run the installer and follow the steps of the installation wizard. Note that MSYS2 requires 64 bit Windows 8.1 or newer. -1. 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 "Run MSYS2 now" box is checked and click "Finish". This will open a MSYS2 terminal window for you. +1. 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 **Run MSYS2 now** box is checked and select **Finish**. This will open a MSYS2 terminal window for you. 1. In this terminal, install the MinGW-w64 toolchain by running the following command. ```MSYS2 @@ -40,7 +40,7 @@ pacman -S --needed base-devel mingw-w64-ucrt-x86_64-toolchain ``` -1. Accept the default number of packages in the `toolchain` troup by pressing the `Enter` key. +1. Accept the default number of packages in the `toolchain` troup by pressing kbstyle(Enter). ![MYSS2 Installer](images/cpp/cpp-install-MSYS2-toolchain.png) @@ -129,7 +129,7 @@ You can also enable [Auto Save](/docs/editor/codebasics.md#save-auto-save) to au ## Explore IntelliSense -[IntelliSense](/editor/intellisense) is a tool to help you code faster and more efficently by adding code editing features such as code completion, parameter info, quick info, and member lists. +[IntelliSense](/docs/editor/intellisense.md) is a tool to help you code faster and more efficently by adding code editing features such as code completion, parameter info, quick info, and member lists. To see IntelliSense in action, hover over `vector` or `string` to see their type information. If you type `msg.` in line 10, you can see a completion list of recommended member functions to call, all generated by IntelliSense: @@ -138,7 +138,7 @@ hover over `vector` or `string` to see their type information. If you type `msg You can press the `kbstyle(Tab)` key to insert a selected member. If you then add open parenthesis, IntelliSense will show information on which arguments are required. -If IntelliSense is not already configured, open the command palette (`kb(workbench.action.showCommands)`) and enter **Select IntelliSense Configuration**. From the dropdown of compilers, select `Use gcc.exe` to configure. +If IntelliSense is not already configured, open the Command Palette (`kb(workbench.action.showCommands)`) and enter **Select IntelliSense Configuration**. From the dropdown of compilers, select `Use gcc.exe` to configure. ## Run helloworld.cpp @@ -209,7 +209,7 @@ The `label` value is what you will see in the tasks list; you can name this what The `detail` value is what you will as the description of the task in the tasks list. It's highly recommended to rename this value to differentiate it from similar tasks. -From now on, the play button will read from `tasks.json` to figure out how to build and run your program. You can define multiple build tasks in `tasks.json`, 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 **Tasks: Configure Default Build Task** in the command palette. Alternatively you can modify the `tasks.json` file and remove the default by replacing this segment: +From now on, the play button will read from `tasks.json` to figure out how to build and run your program. You can define multiple build tasks in `tasks.json`, 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 **Tasks: Configure Default Build Task** in the Command Palette. Alternatively you can modify the `tasks.json` file and remove the default by replacing this segment: ```json "group": { @@ -233,7 +233,7 @@ You can modify your `tasks.json` to build multiple C++ files by using an argumen To debug your code, 1. Go back to `helloworld.cpp` so that it is the active file. -2. Set a breakpoint by clicking on the editor margin or using F9 on the current line. +2. Set a breakpoint by selecting the editor margin or using F9 on the current line. ![screenshot of breakpoint in helloworld.cpp](images/playbutton/cpp-breakpoint.png) 3. From the drop-down next to the play button, select **Debug C/C++ File**. @@ -241,7 +241,7 @@ To debug your code, 4. Choose **C/C++: g++ build and debug active file** 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 `helloworld.cpp`). ![C++ debug configuration dropdown](images/playbutton/select-gcc-compiler.png) -The play button has two modes: **Run C/C++ File** and **Debug C/C++ File**. It will default to the last-used mode. If you see the debug icon in the play button, you can just click the play button to debug, instead of using the drop-down. +The play button has two modes: **Run C/C++ File** and **Debug C/C++ File**. 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. ## Explore the debugger From a14392d035d76276f64f4a36f42e4fed7bea6bc0 Mon Sep 17 00:00:00 2001 From: alkemper_microsoft Date: Mon, 17 Jul 2023 14:21:07 -0700 Subject: [PATCH 4/6] Backticks around kbstyle --- docs/cpp/config-mingw.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/cpp/config-mingw.md b/docs/cpp/config-mingw.md index 1e3278f9fb..9669d3d602 100644 --- a/docs/cpp/config-mingw.md +++ b/docs/cpp/config-mingw.md @@ -40,7 +40,7 @@ pacman -S --needed base-devel mingw-w64-ucrt-x86_64-toolchain ``` -1. Accept the default number of packages in the `toolchain` troup by pressing kbstyle(Enter). +1. Accept the default number of packages in the `toolchain` troup by pressing `kbstyle(Enter)`. ![MYSS2 Installer](images/cpp/cpp-install-MSYS2-toolchain.png) From 6ab24d58a53f504e0074961695da65822272f87f Mon Sep 17 00:00:00 2001 From: Greg Van Liew Date: Mon, 17 Jul 2023 14:36:02 -0700 Subject: [PATCH 5/6] small edits indent pacman step to try and get numbering to work --- docs/cpp/config-mingw.md | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/docs/cpp/config-mingw.md b/docs/cpp/config-mingw.md index 9669d3d602..c81bc6f4ca 100644 --- a/docs/cpp/config-mingw.md +++ b/docs/cpp/config-mingw.md @@ -26,6 +26,7 @@ To successfully complete this tutorial, you must do the following steps: ![C/C++ extension](images/cpp/cpp-extension.png) ## Installing the MinGW-w64 toolchain + Get the latest version of MinGW-w64 via [MSYS2](https://www.msys2.org/), 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 [IntelliSense](/docs/editor/intellisense.md). You can download the latest installer from the MSYS2 page or use this [**direct link to the installer**](https://github.com/msys2/msys2-installer/releases/download/2023-05-26/msys2-x86_64-20230526.exe). @@ -34,11 +35,11 @@ You can download the latest installer from the MSYS2 page or use this [**direct 1. 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 **Run MSYS2 now** box is checked and select **Finish**. This will open a MSYS2 terminal window for you. -1. In this terminal, install the MinGW-w64 toolchain by running the following command. -```MSYS2 -pacman -S --needed base-devel mingw-w64-ucrt-x86_64-toolchain -``` - +1. In this terminal, install the MinGW-w64 toolchain by running the following command: + + ```MSYS2 + pacman -S --needed base-devel mingw-w64-ucrt-x86_64-toolchain + ``` 1. Accept the default number of packages in the `toolchain` troup by pressing `kbstyle(Enter)`. @@ -63,6 +64,7 @@ g++ --version gdb --version ``` You should see output that states which versions of GCC, g++ and GDB you have installed. If this is not the case: + 1. Make sure your PATH variable entry matches the MinGW-w64 binary location where the toochain was installed. If the compilers do not exist at that PATH entry, make sure you followed the previous instructions. 2. If `gcc` has the correct output but not `gdb`, then you need to install the packages you are missing from the MinGW-w64 toolset. - If on compilation your are getting the "The value of miDebuggerPath is invalid." message, one cause can be you are missing the `mingw-w64-gdb` package. From 84f59bf76a23444605796de98dfb0cf027bcec75 Mon Sep 17 00:00:00 2001 From: alkemper_microsoft Date: Wed, 19 Jul 2023 14:30:46 -0700 Subject: [PATCH 6/6] removing UCRT --- docs/cpp/config-mingw.md | 19 +++++-------------- .../cpp/cpp-install-MSYS2-toolchain.png | 4 ++-- 2 files changed, 7 insertions(+), 16 deletions(-) diff --git a/docs/cpp/config-mingw.md b/docs/cpp/config-mingw.md index c81bc6f4ca..18d0861e4b 100644 --- a/docs/cpp/config-mingw.md +++ b/docs/cpp/config-mingw.md @@ -36,9 +36,9 @@ You can download the latest installer from the MSYS2 page or use this [**direct 1. 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 **Run MSYS2 now** box is checked and select **Finish**. This will open a MSYS2 terminal window for you. 1. In this terminal, install the MinGW-w64 toolchain by running the following command: - + ```MSYS2 - pacman -S --needed base-devel mingw-w64-ucrt-x86_64-toolchain + pacman -S --needed base-devel mingw-w64-x86_64-toolchain ``` 1. Accept the default number of packages in the `toolchain` troup by pressing `kbstyle(Enter)`. @@ -51,7 +51,7 @@ You can download the latest installer from the MSYS2 page or use this [**direct 1. In the Windows search bar, type **Settings** to open your Windows Settings. 1. Search for **Edit environment variables for your account**. 1. In your **User variables**, select the `Path` variable and then select **Edit**. - 1. Select **New** 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: `C:\msys64\ucrt64\bin`. + 1. Select **New** 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: `C:\msys64\mingw64\bin`. 1. Select **OK** to save the updated PATH. You will need to reopen any console windows for the new PATH location to be available. ### Check your MinGW installation @@ -175,7 +175,7 @@ Your new `tasks.json` file should look similar to the JSON below: { "type": "cppbuild", "label": "C/C++: g++.exe build active file", - "command": "C:\\msys64\\ucrt64\\bin\\g++.exe", + "command": "C:\\msys64\\mingw64\\bin\\g++.exe", "args": [ "-fdiagnostics-color=always", "-g", @@ -334,7 +334,7 @@ VS Code creates a `launch.json` file in the `.vscode` folder`, which looks somet "environment": [], "externalConsole": false, "MIMode": "gdb", - "miDebuggerPath": "C:\\msys64\\ucrt64\\bin\\gdb.exe", + "miDebuggerPath": "C:\\msys64\\mingw64\\bin\\gdb.exe", "setupCommands": [ { "description": "Enable pretty-printing for gdb", @@ -424,15 +424,6 @@ If you have Visual Studio or WSL installed, you may need to change `compilerPath You must follow the steps on the [MSYS2 website](https://www.msys2.org/) and use the MSYS CLI to install MinGW-w64, which contains those tools. You will also need to install the full MinGW-w64 toolchain (`pacman -S --needed base-devel mingw-w64-x86_64-toolchain`) to get the `gdb` debugger. -### As a Windows user, running the pacman command gives me an error - -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: - -```MSYS2 -pacman -S --needed base-devel mingw-w64-x86_64-toolchain -``` - -When adding the the MinGW-w64 destination folder to your list of environment variables, the default path will then be: `C:\msys64\mingw64\bin`. ### MinGW 32-bit diff --git a/docs/cpp/images/cpp/cpp-install-MSYS2-toolchain.png b/docs/cpp/images/cpp/cpp-install-MSYS2-toolchain.png index 9bbf4d4e20..899f56335c 100644 --- a/docs/cpp/images/cpp/cpp-install-MSYS2-toolchain.png +++ b/docs/cpp/images/cpp/cpp-install-MSYS2-toolchain.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:e8267d9937b0e24db71cb4c5e261c322cd2d9b02d7ea39bf1c85d0be462aa771 -size 721766 +oid sha256:4b2361c282d727daa003553136d28c1b5eff59ca944a55a6b3808d84d9af1821 +size 599395