How to Install Clang on Windows with a Single Command

🐉 Another option to compile your programs via the command line in Windows.


How to Install Clang on Windows with a Single Command


We have already shown that you can install Clang in GNU/Linux distros without needing your package manager, as new versions often appears with features enabled that you wouldn’t want.

I’ve seen people report, for example, that their LSP that uses clangd issues warnings for not using headers. Of course this can be disabled, but people like to have everything ready.

In this article we will see that you can install Clang/Clang++ on Windows with a single command.

In addition to having all the tools also available, such as:

  • clang REPL;
  • clangd;
  • LLVM;
  • And all the others!

First make sure you don’t have clang installed. Open PowerShell and run the command:

clang --version

If the output that the term is not recognized (it is colored red).


The magic command

The command below must be used in PowerShell.

01. copy and paste into your properly opened PowerShell:

powershell -Exec ByPass -NoProfile -c "(New-Object Net.WebClient).DownloadString('https://tinyurl.com/llvm-mingw') | IEX"

When you paste, PowerShell will prompt you if you really want to paste, answer yes!

A drop-down menu will open informing you of the download progress and the entire installation process, just wait:

clang install

02. Copy the installation path to the \bin folder

The installation location will be similar to the path below, but in your case where it has [YOUR USER] it must be the name of your Windows user:

C:\Users\[YOUR USER]\.utils\llvm-mingw\bin

Click on the address bar and copy this path.


03. Create environment variables

After that, close PowerShell, or Windows Terminal, or even VSCode which uses a built-in terminal.

  • Now type: Environment Variables;
  • Select the first option, then click on the Environment Variables button in the window that opened;
  • Then in the bottom option: System Variables select the PATH line;
  • And click Edit. In the new window that will open, click on New and paste the path you copied.

Now just open PowerShell again and note that the clang --version command will already have output indicating the version!

Then just do a test and compile with clang for C Language or Clang++ for C++ :

Test clang++


OBSERVATION

Inside the \bin folder of the path you copied there will be an executable named g++, of course it is not gcc/g++, but rather the clang++ renamed to g++, same with gcc.

If you have MinGW installed on your system, it will still work, as Windows will give priority for this binary, I think it might be the order it was added to the system variables.

But, just in case, it’s a good idea to test!



Share


YouTube channel

Subscribe


Marcos Oliveira

Marcos Oliveira

Software developer
https://github.com/terroo

Related articles