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.
Table of Contents
Downloads
-
Open your web browser and load the official project website of the MinGW-w64 project:
In fact, we can go straight to the download section:
-
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 withmake
andPython
(Version >= 3.9). -
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.
-
We need to understand which version we want to download. A brief explanation is found on the project homepage on Github:
We want to work on Windows directly, so we look for Zip-files called
llvm-mingw-<version>-<crt>-<arch>.zip
where
-
<version>
- A running number that simply indicates the version of the package -
<crt>
- The C runtime library required, which is eithermscvrt
orucrt
. 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. -
<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 All the possible packages contain 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 be20231003
.
You must adapt the following lines according to your choice of package, and likely your version number will be more advanced.Whatever package you choose, download the Zip file.
-
Installing and testing clang and make
- The installation begins with simply unpacking the
.zip
archive and transferring the folder to a convenient location. For simplicity, we will put our copy in the top folder of the main driveC:\
. All the binaries are now contained in:
C:\llvm-mingw-20231003-msvcrt-x86_64
- The most important subfolder is:
C:\llvm-mingw-20231003-msvcrt-x86_64\bin
which contains the binaries that we want to invoke.
-
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
, thenSystem and Security
, thenSystem
, then look for Advanced System Settings.
- Open the launcher and enter
Once the Advanced System Settings dialog is open, titled
System Properties
, open the tab Advanced and click on Environment Variables....-
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 remaining open dialogues.
-
The installation should be ready to use by now.
We can try either Git Bash, Cygwin, Windows PowerShell, or the Methuselian cmd.exe.
All of these load the Windows path variable.- Open any of those command prompts and enter:
clang --version
That should display some self-description of Clang, including the version number.
- 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.- You can look up any of the other commands in the binary folder if you need something else.
One word of caution: different command prompts will try to look up the corresponding binaries in various places, prioritizing one folder over another.
- For example, when calling
gcc
, Cygwin will first look in its own internal directories forgcc
before any MinGW32 implementation. So if your Cygwin installation already includes GCC, then Cygwin will pick that one. - Another example: calling
make
in Cygwin will call the binary at/usr/bin/make
, butmingw32-make
will be found in your Windows system.
Unix utilities on Windows PowerShell
We focus now on Makefiles and their use via Windows PowerShell:
if your makefiles have been 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 astouch
,cp
, and so on).There are circumstances, however, where you also want to execute our makefile in Windows PowerShell.
For example, some IDEs for Windows use PowerShell as their standard terminal.
But not all basic Unix utilities are available in their full capacity on Windows (e.g.,cp -p
is missing).
We can make the standard Unix tools available on PowerShell as follows, assuming thatGit Bash
has already been installed.First, check the location of the binary files that come with Git Bash. For instance, that folder might be:
C:\Program Files\Git\usr\bin\
or whatever else is your installation folder for Git Bash
.
We once again modify the Windows path variable.
We open the launcher and enterAdvanced System Settings
.
Alternatively, we openControl Panel
, thenSystem and Security
, thenSystem
, then look forAdvanced System Settings
.Once that Windows is open, named
System Properties
, open the tabAdvanced
and click onEnvironment Variables...
.In the first list, click on
Path
and thenEdit...
.
Click onNew
and enter the path of the binary folder forGit Bash
,
as identified above. Then clickOK
on all open dialogues.Now the Unix commands that come with Git Bash should also be available in Windows PowerShell.
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.
Top comments (0)