I found the below blog useful : https://developers.redhat.com/blog/2021/04/22/remote-llvm-development-with-visual-studio-code#
This talks about remote SSH setup, but all these things can be easily replicated with native vscode install.
Answer from Darshan Bhat on Stack OverflowI want to develop C++ applications using LLVM toolchain on windows with vscode. Does it need mingw or visual studio 2022 for setup? I tried to run a simple c++ program yet it is taking forever to debug.
Videos
Greetings!
I decided to set up VSCode to be able to code in C++ and build my programs using LLVM. So I downloaded official binaries of LLVM 10.0 and installed it on my Windows system, but unfortunately there is no guide on how to make VSCode use LLVM to build projects. Official tutorials suggest using VS C++ compiler or GCC with MinGWx64 and no one seems to be using LLVM on windows for some reason.
I don't want using VS C++ compiler because it will consume too much of my disk space which I don't want to trade and I don't want GCC on MinGW, well, because of MinGW and all the workaround to install it and setup. LLVM seemed to be the easiest option since it has official installer and platform support.
What is the easiest way to setup VSCode for building projects with LLVM on Windows? Or is there a reason to not even try doing so - that'd explain why no one writes guides about that! If it's not recommended to try LLVM for Windows, then what's going to be the best option otherwise? I just want to compile my projects with all the default configurations, I don't care about optimizations and etc. since the projects are just me studying algorithms with C++.
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.