On Windows, Clang is not self-sufficient, and is supposed to be used in combination with an other compiler: either MinGW (GCC) or MSVC. Clang is going to use the standard library (and other libraries/headers) of that compiler, since it doesn't ship with ones of its own.
If you want to use it with MSVC and have it installed, running clang-cl instead of cl should just work.
But since you mentioned VSC, I assume you don't want MSVC. Then...
If you want to use it with MinGW and have it installed, use clang --target=x86_64-w64-windows-gnu instead of gcc, and it should also just work. (That's assuming your MinGW produces 64-bit apps. Replace x86_64 with i686 if it's 32-bit.)
If you don't have MinGW yet, you can get a fresh version from MSYS2. Then you have an option to install their unofficial build of Clang instead of the regular one, which has an advantage of using --target=x86_64-w64-windows-gnu automatically (so you don't have to write it manually).
On Windows, Clang is not self-sufficient, and is supposed to be used in combination with an other compiler: either MinGW (GCC) or MSVC. Clang is going to use the standard library (and other libraries/headers) of that compiler, since it doesn't ship with ones of its own.
If you want to use it with MSVC and have it installed, running clang-cl instead of cl should just work.
But since you mentioned VSC, I assume you don't want MSVC. Then...
If you want to use it with MinGW and have it installed, use clang --target=x86_64-w64-windows-gnu instead of gcc, and it should also just work. (That's assuming your MinGW produces 64-bit apps. Replace x86_64 with i686 if it's 32-bit.)
If you don't have MinGW yet, you can get a fresh version from MSYS2. Then you have an option to install their unofficial build of Clang instead of the regular one, which has an advantage of using --target=x86_64-w64-windows-gnu automatically (so you don't have to write it manually).
Install Clang using Visual Studio Installer.
(1) Open 'Visual Studio Installer'.
(2) Visual Studio Community 2022 -> click 'Modify'
(3) In the [Installation details] checkbox list, check 'C++ Clang tools for Windows'
(4) Install.Add
clang.exe(created by the above procedure) to thePathenvironment variable.Now try
clang --versionin the terminal.
Great, you're good to go :)
Edit: If you didn't change the default installation path, clang.exe should likely be in C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\Llvm such as (for x64) C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\Llvm\x64\bin.
How do I install latest Clang for VSCode? (On Windows10)
CLANG download and install
c++11 - What do you need to install to use Clang on windows to build c++14 for 64 bit? - Stack Overflow
Easy way to install latest Clang on Windows?
Videos
I've been trying to install the latest version of Clang (17.01) on Windows 10 without resorting to MinGW or similar, and without using the VS2022 installer 'cause it still uses v16.
I got the official installer from the LLVM website but not only VS2022 doesn't detect it, VS Code doesn't either. I tried looking for info on Google but got no luck.
I'm beginner, wanting to use VSCode (Visual Studio Code) for C++ projects. I want to try Clang. GCC I have already installed and tried successfully (via MinGW/MSYS). I'm confused about Clang installation though. If I understand correctly, installing latest Clang (from https://github.com/llvm/llvm-project/releases or what not) is alone not enough. That it is "just" the compiler and it needs other things to work, so it has to rely on stuff from either MSVC or MinGW. So what do I do to make it work? (without messing up my current installation of Visual Studio (not VSCode) and the MinGW installation which I want to use for GCC. I want to try the latest stable release if possible so the version in VisualStudio is no good.)
How can I download and install the latest Clang compiler and from where (for windows)?
Try installing MSYS2 and then installing the mingw-w64-x86_64-clang (binary) package:
pacman -S mingw-w64-x86_64-clang
It is a bit old at the moment (3.6.2), but it might be good enough for you. Then when you run the Win64 shell provided by MSYS2, clang will be on your path.
If it's not good enough, I have recently been building a 64-bit version of clang with MSYS2 and using it to compile native 64-bit Windows executables. My process was something like:
- Use pacman to install base-devel, mingw-w64-x86_64-ninja, mingw-x86_64-cmake and perhaps some other packages that are needed by the build process.
- Grab my PKGBUILD script for clang and the files in the same directory. This is based on the mingw-w64-clang-svn package from MSYS2, which is largely the work of Martell Malone. You can find him on the MSYS2 IRC channel and ask him more about it.
- In a Win64, shell, go to the directory with my PKGDUILD, run
export MINGW_INSTALLS=mingw64(so you are only compiling the 64-bit version), and then runmakepkg-mingw.
It is unlikely you will get everything right on the first try, and some files might need to be edited. Clang may have changed since the last time I did this and some patches might not apply cleanly.
if you use the upcoming clang 3.7.0, simply set PATH to include mingw-w64's bin, clang will work as you expect
As utilities, clang-format and git-clang-format are available in several forms:
- As a part of
clang.
[As noted by OP in the final comments below, and with OP's answer to their own question, these should be included with MSYS2/MingGW on Windows].
As pre-compiled Python wheels for Linux and Windows available via
pip(PyPI).As modules available for Node.js. On Windows, use the standard Windows installer to install Node.js. Otherwise, example Linux package manager commands for installing Node.js are here.
Python
For Python versions on Linux or Windows, you may wish to try:
python3 -m pip install clang-format
Node.js
Assuming Node.js is installed, you can also get them both with:
npm install -g clang-format
Note that on Windows, using the Node.js option seems to be the simplest solution for obtaining just clang-format and git-clang-format (without installing MinGW).
You can get it as part of the LLVM compiler build for Windows. You can download it from https://llvm.org/builds/. Once installed, clang-format.exe can be found in C:\Program Files\LLVM\bin.
I know it's a bit heavy to install the whole compiler just to get the formatter, but yeah, it just feels safer compared to other sources, given that it's from LLVM itself.
Besides, the installer holds an archive that several tools (e.g. 7-Zip) can open. If you have downloaded the installer, but do not want to install the whole thing, extract the single executable from the archive under bin.