Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using Clang in windows 10 for C/C++

I am currently learning C, taking a CS50 online class via EDX/Harvard. They have us using Clang inside the CS50 IDE/Sandbox which is cloud-based. They haven't explained how to use Clang outside of that tho. Thus I am wondering; How do I setup clang in windows 10 ? as well as for use with VisualStudio Code?

like image 477
Josh Gray Avatar asked Dec 06 '25 13:12

Josh Gray


2 Answers

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).

like image 111
HolyBlackCat Avatar answered Dec 08 '25 05:12

HolyBlackCat


  1. 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.

  2. Add clang.exe (created by the above procedure) to the Path environment variable.

  3. Now try clang --version in 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.

like image 35
starriet Avatar answered Dec 08 '25 07:12

starriet



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!