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.
-
Start the installer and note the chosen installation path (e.g.
C:\msys64). It is best to keep the default path. -
If necessary, close the shell that the installer opens automatically.
-
Start the UCRT64 shell by running the program
ucrt64.exe(e.g.C:\msys64\ucrt64.exe). -
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-gdbWhen copying, make sure that no additional characters are inserted before the command, and remove them if necessary.
-
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.
- Type
Environment(German:Umgebungsvariablen) into the Windows search and click on the optionEdit the system environment variables(German:Systemumgebungsvariablen bearbeiten). - In the new window, click the
Environment Variablesbutton (German:Umgebungsvariablen). Another window opens. Double-click thePathentry there. - In the new window, click the
Newbutton (German:Neu) and insert the path to thebinsubfolder of the UCRT64 environment (e.g.C:\msys64\ucrt64\bin). - Close all three open windows in reverse order by clicking
OK. - Check whether the compiler installation and the path change were successful:
- Start PowerShell: press the Windows key, type
PowerShelland click onWindows PowerShell. - Enter
g++ --versionin 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!
- Start PowerShell: press the Windows key, type
3. Installing Visual Studio Code
- Download Visual Studio Code as an installer.
- 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
.cppfile 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:
- 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 fileg++.exe. - 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).