Clang/LLVM Support in Visual Studio
For up-to-date documentation see Clang/LLVM support in Visual Studio projects.
For an overview of the Visual Studio capabilities described in this article, see Develop C and C++ applications.
Visual Studio 2019 includes out of the box support for editing, building, and debugging CMake projects with Clang/LLVM. If you use MSBuild projects, however, don’t worry. Support for MSBuild based .vcxproj projects is coming soon as well. If you are not familiar with Visual Studio’s CMake, support check out how to get started.
If you are developing on Windows and targeting Clang, we hope to make Visual Studio the best IDE for that job. Please try out the preview and let us know what is working well and what isn’t.
Installing Clang/LLVM for use with Visual Studio
The “Desktop development with C++” workload with the Visual Studio installer now includes full support for targeting Clang/LLVM based toolsets. You will also need the actual compiler and tools to build your projects.
Getting Clang on Windows
On Windows, it’s easy to install the Clang tools. Just grab the “Clang compiler for Windows,” an optional component of the “Desktop development with C++” workload. This will install everything you need to develop with Clang on Windows.
You can also install your own copy of Clang/LLVM or even build it from source. If you have already installed Clang/LLVM you don’t need to install the compiler again with the Visual Studio installer. We do recommend that you use the most recent version of Clang to get the best support in the IDE. Older versions may have some limitations. Check out “Using a Custom Version of Clang” below for more information.
Getting Clang on Linux
To use Clang/LLVM on a remote Linux machine with Visual Studio, just install it with your distribution’s package manager. If ‘which clang’ finds the compiler you are good to go.
Getting Started with Clang/LLVM in Visual Studio
Once you have installed Clang, using it with CMake projects is easy. Visual Studio will use the MSVC compiler by default on Windows. On Linux, it will use the distribution’s default compiler, often GCC. To use Clang instead, add a configuration and select one of the Clang presets.
Select “Manage Configurations” from the configuration drop down on the left of the play button. Then click the “Add Configuration” button:
Another option is to modify an existing configuration with the CMake Settings editor to use any of the “clang” toolsets with the Toolset dropdown:
These toolsets will use Clang in clang-cl mode by default on Windows and link with the Microsoft STL. If you are targeting Linux, they will use Clang in GCC compatibility mode. Toolsets to build both 32 and 64-bit binaries are available on Windows while the Linux toolsets will target the architecture of the remote machine. Most of this behavior can be tweaked by customizing either the CMake command line or in the CMake project itself.
Edit, Build, and Debug
Once you have set up a Clang configuration, build and debug work exactly as you would expect in the IDE. Visual Studio will automatically detect that you are using the Clang compiler and provide applicable IntelliSense, highlighting, navigation, and other editing features. Building projects should just work, provided they are compatible with Clang, with any errors or warnings being directed to the Output Window.
Whether you are targeting Windows or Linux, the debugging experience with Clang should be familiar to you. Most of Visual Studio’s debugging features also work with Clang. There are just a few exceptions for compiler dependent features (e.g. edit and continue.) Breakpoints, memory and data visualization, and other inner development loop debugging features are available:
Using a Custom Installation of Clang
Visual Studio will automatically look for Clang in two places:
- (Windows) The internally installed copy of Clang/LLVM that comes with the Visual Studio installer.
- (Windows and Linux) The PATH environment variable.
If it doesn’t find Clang in one of those places it will offer to install it on Windows. On Linux, you will need to install it with the distribution’s package manager. Alternatively, you can tell Visual Studio to use another installation of Clang/LLVM on the machine by setting the “CMAKE_C_COMPILER” and “CMAKE_CXX_COMPILER” CMake variables in your CMake Settings:
Keep in mind, however, that using old versions of Clang may come with some limitations. For instance, if you are using the Microsoft STL on Windows, support is only gaurenteed for the most recent version of the compiler. As we release new versions of Visual Studio and the Microsoft STL you may need to upgrade your custom installation.
Using Clang/LLVM with MSBuild Projects
Visual Studio 2019 version 16.1 ships with out of the box support for Clang/LLVM for CMake projects. Support for MSBuild based C++ projects is on the roadmap and will be available soon in a future release. To use Clang/LLVM today with MSBuild based C++ projects there are 3rd party extensions for Visual Studio available.
Send Us Feedback
Please try out the latest preview and let us know if you have any feedback. It is always appreciated! The best way to get in touch with us about an issue or suggestion is though Developer Community with the “Report a Problem” or “Suggest a Feature” tools. This makes it easy for us to follow up and for you to get the latest updates about our progress. Feel free to comment here or send an email to firstname.lastname@example.org with questions as well.
“To use Clang/LLVM today with MSBuild based C++ projects there are 3rd party extensions for Visual Studio available”
It could be worth linking to these 3rd party extensions
Thanks. I’ve updated the post with a link: https://marketplace.visualstudio.com/items?itemName=LLVMExtensions.llvm-toolchain
I assumed you meant that one but it says: “Works with:Visual Studio 2017”
Does that mean it also works with VS2019?
This is very exciting for us. In particular I’m looking forward toseeing an official msbuild toolset so we can deprecatehttps://marketplace.visualstudio.com/items?itemName=LLVMExtensions.llvm-toolchainAny plans on adding lld support to the toolset and installer?Also was there any reason you didn’t include the more recent 8.0.0release in the installer, or just timing? As release manager I’d bekeen to know if you saw any issues with that release, or if you wantto be involved in the process of future releases.Congratulations on this work, and thanks for a good blog post!
(I tried emailing the address in the post, but it bounced.)
Hi Hans. Thanks for the heads up about the issues with email@example.com. The bounce issue should be fixed now and we’ve replied to your original email.
For those following the comments: We’ll update to Clang 8 soon. Shipping Clang 7 just came down to timing of the releases of Visual Studio and Clang. We are strongly considering adding built in lld support too. If people are intersting in this, please let us know.
In order for LTO/ThinLTO to work lld support is required. As LTCG is not implemented in Clang/LLVM, the use of lld seems to be almost obligatory.
It worked pretty well with VS 2019! :DI suggest the post to add how to install LLVM packages via chocolatey(https://chocolatey.org/) shortly. It installs latest clang-cl and config PATH automatically.
Instead of doing remote compilation, has there been any thought using clang locally to cross compile to Linux instead of doing remote compilations? Presuming that all headers / libraries / whatever else are already local. Specifically with the MSBuild integration?
I was wondering if you had given any thought to letting the standard c++ library be selectable independent of compiler. My undertanding is that the gcc/clang/cl compilers can use libc++/libstdc++/MSVC standard library in maybe not all but most combinations.
Please search for clang-format.exe ,clangd.exe and any clang related executable as well in the PATH before running the included one fromC:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\IDE\VC\vcpackages\clang-format.exe
It appears that <filesystem> cannot be included (at least using clang-cl.exe), there is a weird, relatively unmentioned error:
EXEC : error : cannot mangle this built-in char8_t type yet
I tried it and it failed. You can see the error log here: https://gist.github.com/ImanHosseini/8b696ea81946f6248c73652aa9eaeca0
This is just a fresh hello world CMake project, nothing tweaked/tampered with.
Your search path is incorrect.VS 2019 16.2 has clang in the folder: “C:\Program Files (x86)\Microsoft Visual Studio\2019\<Edition>\VC\Tools\Llvm\8.0.0\bin”
VS 2019 16.3 will have clang in the folder: “C:\Program Files (x86)\Microsoft Visual Studio\2019\<Edition>VC\Tools\Llvm\bin”
Seems that msbuild launches just one clang.exe at a time
I assume the /MP option doesn;t work ?
Does it support OpenMP 4.5 as CLang?
I really hope this integration will give us a more modern OpenMP library.
Yes, I’ve tested it with OpenMP 4.5 code and it works.