Using Clang++ and Make natively on Windows

This guide will explain you how to install Clang++ and Make on Windows: specifically, we will discuss the MinGW-w64 project.

In my experience, getting these programs to run natively on Windows is faster than calling them from within emulation layers such as Cygwin.

Downloads

  1. Open your web browser and load the official project website of the MinGW-w64 project:
    https://www.mingw-w64.org/
    Actually, we can go straight to the download section:
    https://www.mingw-w64.org/downloads
  2. You find several links to different packages of MinGW-w64 bundled together with compilers and additional software. This guide focuses on the LLVM package, LLVM-MinGW, which provides the LLVM compilers and also comes bundled with make and Python (Version >= 3.9).
  3. Use the link on the website or go directly to:
    https://github.com/mstorsjo/llvm-mingw/releases
    Here, you find Zip-files that contain the precompiled binaries, for different processor architectures and operating systems.
  4. We need to understand which version to download. A brief explanation is found on the project homepage on Github:
    https://github.com/mstorsjo/llvm-mingw#releases
    We want to work on Windows directly, so we look for Zip-files called
    llvm-mingw-<version>-<crt>-<arch>.zip
    where
    1. <version> - A running number that simply indicates the version of the package
    2. <crt> - The C runtime library required, which is either mscvrt or ucrt. The former is the MSV C runtime, which is available on all versions of Windows but has less features. The latter is the Universal C runtime, which is pre-installed from Windows 10 onwards. Please note that the Zip-file will not provide that runtime library, you need to make sure that your Windows installation already provides it. For that reason, we will pick the MSV C runtime.
    3. <arch> - This indicates the processor architecture, which is one of the following:
      • i686, which is the 32-bit architecture of Intel
      • x86-64, which is the 64-bit architecture of Intel
      • armv7, which is the 32-bit architecture of ARM
      • aarch64, which is the 64-bit architecture of ARM
      The package contains binaries to compile for any of those architectures but these binaries only run on the specified architecture. For that reason, you need look up which processor is being used on your machine and pick the appropriate package.
    Let us suppose from now on that we have picked 64-bit Intel CPU and, just for compatibility reasons, use the MSV C runtime. The version will be 20231003. You must adapt the following lines according to your choice of package, and likely your version number will be more advanced.

    Whatever you pick, download the Zip file.

Installing and testing clang and make

  1. The installation begins with simply unpacking the .zip archive and transfering the folder to a convenient location. For simplicity, we choose the put our copy to the top folder folder of the main drive C:\. All the binaries are now contained in
    C:\llvm-mingw-20231003-msvcrt-x86_64
  2. The most important subfolder is
    C:\llvm-mingw-20231003-msvcrt-x86_64\bin
    which contains the binaries that we want to evoke.
  3. We modify the Windows path variable. For that, we need to access the "Advanced System Settings". Open the launcher and enter Advanced System Settings. Alternatively, open Control Panel, then System and Security, then System, then look for Advanced System Settings.
  4. Once that Windows is open, named System Properties, open the tab Advanced and click on Environment Variables...
  5. In the first list, click on Path and then Edit.... Click on New and enter the path of the binary folder. In our example, C:\llvm-mingw-20231003-msvcrt-x86_64\bin. Then click OK on all open dialogues.
  6. Congratulations, we should be ready now. We can try either Git Bash, Cygwin, Windows Powershell, or the Methuselian cmd.exe. All of these load the Windows path variable
    1. Open any of those command prompts and enter clang --version. That should display some self-description of Clang, including the version number.
    2. Make has a different name in this package. Open any of the aforementioned command prompts and enter mingw32-make --version. Again, you will receive the version output of your current make implementation.
    3. You can look up any of the other commands in the binary folder if you have need for something else.
    One of word of caution: different command prompts give different priorities to different folders when looking for the command. For example, Cygwin will first look in its own internal directories for gcc, so if your Cygwin installations already includes GCC, then Cygwin will pick that one. Typically, calling make in Cygwin will call the binary at /usr/bin/make but mingw32-make will be found in your Windows system.

Unix utilities on Windows PowerShell

  1. One more issue concerning makefiles: if your makefiles are developed for a Unix environment, then you may encounter difficulties when executing make on Windows. Things will typically work fine when the shell is, say, Git Bash, which provides the most basic Unix utilities (such as touch, cp, and so on).
  2. However, it is desirable if we can also execute our makefile from Windows PowerShell. For example, some IDEs for Windows use PowerShell as their standard terminal. We can to make the standard Unix tools available on PowerShell as follows, assuming that Git Bash has already been installed.
  3. First, check the location of the binary files that come with Git Bash. For example, that folder might be
    C:\Program Files\Git\usr\bin\
    or whatever else is your installation folder for Git Bash.
  4. We once again modify the Windows path variable. We open the launcher and enter Advanced System Settings. Alternatively, we open Control Panel, then System and Security, then System, then look for Advanced System Settings.
  5. Once that Windows is open, named System Properties, open the tab Advanced and click on Environment Variables...
  6. In the first list, click on Path and then Edit.... Click on New and enter the path of the binary folder for Git Bash, as identified above. Then click OK on all open dialogues.
  7. Now the Unix commands that come with Git Bash should also be available in Windows PowerShell. Congratulations, we should be ready now. To test that, open a Windows PowerShell terminal, and type something like touch --version. You should now see what you would expect on Linux as well. Similarly, the same should now work on the classical Windows command line terminal.