Skip to main content

Private Computer — Windows

1. Installing GCC​

Depending on your computer, you need to install a compiler for x64 (also called x86_64) or for ARM. How to find out which one you have is explained in the installation overview. Most Windows laptops use x64.

a. GCC (x64)​

As the compiler, we install GCC in the UCRT64 environment of MSYS2. This environment uses the current C runtime library of Windows (Universal C Runtime) and is recommended by the MSYS2 project. This only works on 64-bit x86 Windows systems. You use MSYS2 as the installation tool.

  1. Download the installer.

  2. Start the installer and note the chosen installation path (e.g. C:\msys64). It is best to keep the default path.

  3. If necessary, close the shell that the installer opens automatically.

  4. Start the UCRT64 shell by running the program ucrt64.exe (e.g. C:\msys64\ucrt64.exe).

  5. Run the following command in the MSYS2 terminal and confirm each installation prompt with Y:

    pacman -S mingw-w64-ucrt-x86_64-gcc mingw-w64-ucrt-x86_64-gdb

    When copying, make sure that no additional characters are inserted before the command, and remove them if necessary.

  6. Wait for the installation to finish.

b. GCC for Windows 11 (ARM)​

On ARM-based computers (e.g. Surface Pro X or laptops with a Snapdragon processor), please follow the MSYS2 guide for ARM64. If you run into problems, we are happy to help you in the tutorial.

2. Adding GCC to the path​

Now you need to add the installed compiler to the execution path so that Visual Studio Code can find it.

  1. Type Environment (German: Umgebungsvariablen) into the Windows search and click on the option Edit the system environment variables (German: Systemumgebungsvariablen bearbeiten).
  2. In the new window, click the Environment Variables button (German: Umgebungsvariablen). Another window opens. Double-click the Path entry there.
  3. In the new window, click the New button (German: Neu) and insert the path to the bin subfolder of the UCRT64 environment (e.g. C:\msys64\ucrt64\bin).
  4. Close all three open windows in reverse order by clicking OK.
  5. Check whether the compiler installation and the path change were successful:
    • Start PowerShell: press the Windows key, type PowerShell and click on Windows PowerShell.
    • Enter g++ --version in the new window.
    • An output should appear that starts with g++ and contains a version number.
    • If an error message appears instead saying that g++ is not recognized, a step was not carried out correctly. In this case, first check what did not work!

3. Installing Visual Studio Code​

  1. Download Visual Studio Code as an installer.
  2. Run the installer and go through the steps. Make sure that the installation path does not contain any umlauts (ä, ö, ü, ß, …).

Setting up Visual Studio Code is described in the main guide.

4. FAQ and problems​

Below you will find problems that frequently occur on Windows. If you cannot find a solution to your problem here, please also check the general FAQ.

When compiling: cc1plus: fatal error: *.cpp: No such file or directory​

Problem: No source file is found.

Cause: On 03.11.2024, MSYS2 changed its default settings ("Disabling mingw-w64 wildcard support by default"). Since then, the wildcard *.cpp is no longer expanded to the matching file names but is used literally as a file name.

Solution: Open the file .vscode/tasks.json in your project folder and look for the entry with *.cpp in the args section:

"args": [
"-fdiagnostics-color=always",
"-g",
"${fileDirname}\\*.cpp",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
  • Program consisting of a single file: Replace "${fileDirname}\\*.cpp" with "${file}". Then the currently open file is always compiled.

  • Program consisting of several files: Replace "${fileDirname}\\*.cpp" with one entry per file, e.g.:

    "args": [
    "-fdiagnostics-color=always",
    "-g",
    "${fileDirname}\\main.cpp",
    "${fileDirname}\\bitmap.cpp",
    "-o",
    "${fileDirname}\\${fileBasenameNoExtension}.exe"
    ],

    If you add another .cpp file later, you must add it here as well.

Special characters in the folder name​

Problem: If the name of the folder containing the source files includes special characters, e.g. C:\Users\Görschwin Fey\meineProgramme or C:\tmpö, the default compilation in Visual Studio Code does not work.

Solution: Create and use a different folder without special characters.

Compiler not found (g++ option missing after pressing the play button)​

Problem: After pressing the play button, Visual Studio Code does not offer an option with g++ or cannot find a C++ compiler. g++ --version reports in the terminal that g++ is not recognized.

Solution:

  1. Check whether you have completed step 2 (adding GCC to the path) and whether the path you entered (e.g. C:\msys64\ucrt64\bin) actually exists and contains the file g++.exe.
  2. Then completely close Visual Studio Code and all open terminals and reopen them. Changes to the path only take effect after the programs have been restarted.

#include <iostream> is underlined in red​

Problem: Visual Studio Code tries to determine while you are programming whether the file can be compiled. Despite this "error message", you can compile and run the file without any problems! The message appears because Visual Studio Code does not know which files are shipped with your compiler.

Solution: To make these files known to Visual Studio Code, click on the Win32 option in the blue bar at the bottom and then select Edit Configurations (UI). In the tab that opens, under Compiler path, select the option that ends with g++.exe (e.g. C:\msys64\ucrt64\bin\g++.exe). You can then close the tab, and the "error message" should disappear.

Can not open output file / Permission denied​

Problem: Some antivirus programs (e.g. Avira) prevent write operations in the Documents folder.

Solution: Open the antivirus program and exclude the affected folder from the virus scan (Avira example, in German).