Installing C++ (mingw-w64)

Installing C++ (mingw-w64)

21/12/2022

I’ve been trying to improve upon my C++ although one of the things I hate the most about development within C++ is the build system.

Installing compilers and understanding the best way to install them has proven difficult for me and so I’m going to write down the recipe that has worked for me:

Using MSYS2

MSYS2 is a software distribution and building platform for Windows. We are using it to install Mingw-w64. Within this, we need to install the correct architecture for our computer which is most likely x86 64-bit. Once all of the installing has happened, our directory will look like this:

📂 C:\msys2
┗ 📂 mingw64
  ┗ 📂 x84_64_w64-mingw32

I’ve taken bits from various tutorials. Microsoft have a great basic one which is nice to follow.

C++ installation

  1. Install the C/C++ VS Code extension. Make sure to use the Microsoft one.

  2. Install MSYS2.

  3. Follow the installation instructions on that website (MSYS2) - this will install Mingw-w64.

    The last command you should have entered (except the gcc one) was:

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

    Make sure to stick around in the UCRT64 environment since we are going to use it to install the Mingw-w64 toolchain via pacman:

  4. Install the toolchain via:

    pacman -S --needed base-devel mingw-w64-x86_64-toolchain

    Accept the default installation.

  5. Add mingw64 to your PATH environment variable.

    C:\msys2\mingw64\bin
  6. Now open a terminal and enter gcc --version to verify that everything has installed successfully.

  7. To create C++ projects of medium complexity, we will require CMake. It’s great to get used to using CMake with smaller projects to make it much easier once you start to deal with more complex projects.

    Install CMake via the .msi installer: Download from the official site.

  8. Again, make sure to add this to your PATH environment variable:

    C:\Program Files\CMake\bin
  9. In VS Code, install the CMake extension and the CMake Tools extension.

Overall it’s not that difficult at all but now let’s look at creating a build environment within VS Code.