Windows Setup (MinGW)
Rem. This part is only for advanced users. THe use of Visual Studio is encouraged.
While
MS Visual Studio is the most standard approach to compile C++ on Windows, you may use alternative compiler and IDE. These alternative solution can be lighter than using the full Visual Studio IDE, but require more technical set-up.
-
- Visual Studio Code (VS Code) is a lightweight code editor that can be use to edit C++ code (as well as other programming language).
-
- VS Code is however only a code editor, and doesn't provide a C++ compiler in itself. The general approach is to install a compiler separately, and add it to the Windows path in order to be detected by VS Code.
-
- MinGW is an implementation of the Open-Source gcc compiler on Windows. It is the main alternative to the compiler provided by Visual Studio.
System setup
These steps need to be done only once on a given computer.
Follow the instructions described on
this page to install MinGW and set VS Code.
-
1. Install MSYS2
-
-
MSYS2 is a Software package manager for Windows allowing to install softwares bundles from command lines.
-
2. Install MinGW through MSYS2 (The C++ compiler)
-
-
MinGW is the C++ compiler we will use through VS Code.
pacman -S --needed base-devel mingw-w64-x86_64-toolchain
-
3. Add MinGW compiler to the Windows path.
-
-
Allow to call g++ from the command line, and enable VS Code to detect the path to the compiler.
Compiling in VS Code
This step needs to be done every time you will open a C++ project.
Let us consider the
root_directory of the project (directory with the CMakeLists.txt) to be
examples/example_compilation/
-
This directory can be adapted to any other scene example.
-
1. Open the directory root_directory in VS Code using "File" \(\rightarrow\) "Open Folder".
-
Rem. Don't open directly a .cpp/.hpp file in VS Code, otherwise you will not load the entire project, but only a single file.
-
2. Compile the code in selecting the "Build" option in the taskbar on the bottom of the window.
-
-
Select the compiler "GCC" associated to the MinGW path that should appear in the choices.
Once compiled, the file
build/example_compilation.exe should be generated. You can run the executable either:
-
- In double-clicking on this file
-
- In typing on the VS Code terminal:
.\build\example_compilation.exe