{"id":24155,"date":"2019-04-24T17:01:39","date_gmt":"2019-04-24T17:01:39","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/cppblog\/?p=24155"},"modified":"2022-08-23T18:53:12","modified_gmt":"2022-08-23T18:53:12","slug":"clang-llvm-support-in-visual-studio","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/cppblog\/clang-llvm-support-in-visual-studio\/","title":{"rendered":"Clang\/LLVM Support in Visual Studio"},"content":{"rendered":"<p><div class=\"alert alert-info\"><p class=\"alert-divider\"><i class=\"fabric-icon fabric-icon--Info\"><\/i><strong>Content outdated<\/strong><\/p> For up-to-date documentation see <a class=\"Hyperlink SCXW199939464 BCX8\" href=\"https:\/\/docs.microsoft.com\/en-us\/cpp\/build\/clang-support-msbuild?view=msvc-170\" target=\"_blank\" rel=\"noreferrer noopener\"><span class=\"TextRun Underlined SCXW199939464 BCX8\" lang=\"EN-GB\" xml:lang=\"EN-GB\" data-contrast=\"none\"><span class=\"NormalTextRun SCXW199939464 BCX8\" data-ccp-charstyle=\"Hyperlink\">Clang\/LLVM support in Visual Studio projects<\/span><\/span><\/a>.<\/p>\n<p>For an overview of the Visual Studio capabilities described in this article, see <a href=\"https:\/\/visualstudio.microsoft.com\/vs\/features\/cplusplus\/\">Develop C and C++ applications<\/a>.<\/div><a href=\"https:\/\/visualstudio.microsoft.com\/vs\/preview\/\">Visual Studio 2019 version 16.1 Preview 2<\/a> comes with support for Clang\/LLVM out-of-the-box. Visual Studio has had great tooling for MSVC and GCC for quite a while now. The latest preview brings Clang into the fold.<\/p>\n<p>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\u2019t worry. Support for MSBuild based .vcxproj projects is coming soon as well. If you are not familiar with Visual Studio\u2019s CMake, support <a href=\"https:\/\/aka.ms\/cmake\">check out how to get started<\/a>.<\/p>\n<p>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\u2019t.<\/p>\n<h3>Installing Clang\/LLVM for use with Visual Studio<\/h3>\n<p>The \u201cDesktop development with C++\u201d 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.<\/p>\n<h4>Getting Clang on Windows<\/h4>\n<p>On Windows, it\u2019s easy to install the Clang tools. Just grab the \u201cClang compiler for Windows,\u201d an optional component of the \u201cDesktop development with C++\u201d workload. This will install everything you need to develop with Clang on Windows.<\/p>\n<p><img decoding=\"async\" class=\"size-full wp-image-24156 aligncenter\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2019\/04\/Clang-Compilers-for-Windows-Installer-Annotated.png\" alt=\"Install the \u201cClang compiler for Windows\u201d optional component as part of the \u201cDesktop development with C++\u201d workload.\" width=\"1250\" height=\"628\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2019\/04\/Clang-Compilers-for-Windows-Installer-Annotated.png 1250w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2019\/04\/Clang-Compilers-for-Windows-Installer-Annotated-300x151.png 300w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2019\/04\/Clang-Compilers-for-Windows-Installer-Annotated-768x386.png 768w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2019\/04\/Clang-Compilers-for-Windows-Installer-Annotated-1024x514.png 1024w\" sizes=\"(max-width: 1250px) 100vw, 1250px\" \/><\/p>\n<p>You can also install your own copy of Clang\/LLVM or even <a href=\"https:\/\/clang.llvm.org\/get_started.html\">build it from source<\/a>. If you have already installed Clang\/LLVM you don\u2019t 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 \u201cUsing a Custom Version of Clang\u201d below for more information.<\/p>\n<h4>Getting Clang on Linux<\/h4>\n<p>To use Clang\/LLVM on a remote Linux machine with Visual Studio, just install it with your distribution\u2019s package manager. If \u2018which clang\u2019 finds the compiler you are good to go.<\/p>\n<h3>Getting Started with Clang\/LLVM in Visual Studio<\/h3>\n<p>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\u2019s default compiler, often GCC. To use Clang instead, add a configuration and select one of the Clang presets.<\/p>\n<p>Select \u201cManage Configurations\u201d from the configuration drop down on the left of the play button. Then click the \u201cAdd Configuration\u201d button:<\/p>\n<p><img decoding=\"async\" class=\"wp-image-24157 size-full aligncenter\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2019\/04\/Add-Clang-Configuration.png\" alt=\"Clang for Windows CMake configuration presets.\" width=\"436\" height=\"465\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2019\/04\/Add-Clang-Configuration.png 436w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2019\/04\/Add-Clang-Configuration-281x300.png 281w\" sizes=\"(max-width: 436px) 100vw, 436px\" \/><\/p>\n<p>Another option is to modify an existing configuration with the CMake Settings editor to use any of the \u201cclang\u201d toolsets with the Toolset dropdown:<img decoding=\"async\" class=\"size-full wp-image-24158 aligncenter\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2019\/04\/Clang-Configuration-Toolset-Dropdown.png\" alt=\"\" width=\"1266\" height=\"753\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2019\/04\/Clang-Configuration-Toolset-Dropdown.png 1266w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2019\/04\/Clang-Configuration-Toolset-Dropdown-300x178.png 300w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2019\/04\/Clang-Configuration-Toolset-Dropdown-768x457.png 768w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2019\/04\/Clang-Configuration-Toolset-Dropdown-1024x609.png 1024w\" sizes=\"(max-width: 1266px) 100vw, 1266px\" \/><\/p>\n<p>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 <a href=\"https:\/\/clang.llvm.org\/docs\/ClangCommandLineReference.html\">in the CMake project itself<\/a>.<\/p>\n<h3>Edit, Build, and Debug<\/h3>\n<p>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.<\/p>\n<p>Whether you are targeting Windows or Linux, the debugging experience with Clang should be familiar to you. Most of Visual Studio\u2019s 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:<\/p>\n<p style=\"text-align: center;\"><img decoding=\"async\" class=\"alignnone size-full wp-image-24159\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2019\/04\/Clang-Debugging-Annotated.png\" alt=\"\" width=\"1162\" height=\"761\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2019\/04\/Clang-Debugging-Annotated.png 1162w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2019\/04\/Clang-Debugging-Annotated-300x196.png 300w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2019\/04\/Clang-Debugging-Annotated-768x503.png 768w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2019\/04\/Clang-Debugging-Annotated-1024x671.png 1024w\" sizes=\"(max-width: 1162px) 100vw, 1162px\" \/><\/p>\n<h3>Using a Custom Installation of Clang<\/h3>\n<p>Visual Studio will automatically look for Clang in two places:<\/p>\n<ol>\n<li>(Windows) The internally installed copy of Clang\/LLVM that comes with the Visual Studio installer.<\/li>\n<li>(Windows and Linux) The PATH environment variable.<\/li>\n<\/ol>\n<p>If it doesn\u2019t 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\u2019s package manager. Alternatively, you can tell Visual Studio to use another installation of Clang\/LLVM on the machine by setting the \u201cCMAKE_C_COMPILER\u201d and \u201cCMAKE_CXX_COMPILER\u201d CMake variables in your CMake Settings:<\/p>\n<p style=\"text-align: center;\"><img decoding=\"async\" class=\"alignnone size-full wp-image-24160\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2019\/04\/CMake-Settings-Compiler-Variables.png\" alt=\"Set \u201cCMAKE_C\/CXX_COMPILER\u201d variables with the CMake Settings editor to use a custom Clang installation.\" width=\"943\" height=\"434\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2019\/04\/CMake-Settings-Compiler-Variables.png 943w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2019\/04\/CMake-Settings-Compiler-Variables-300x138.png 300w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2019\/04\/CMake-Settings-Compiler-Variables-768x353.png 768w\" sizes=\"(max-width: 943px) 100vw, 943px\" \/><\/p>\n<p>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.<\/p>\n<h3>Using Clang\/LLVM with MSBuild Projects<\/h3>\n<p>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 <a href=\"https:\/\/marketplace.visualstudio.com\/items?itemName=LLVMExtensions.llvm-toolchain\">3<sup>rd<\/sup> party extensions for Visual Studio available<\/a>.<\/p>\n<h3>Send Us Feedback<\/h3>\n<p>Please try out the <a href=\"https:\/\/visualstudio.microsoft.com\/vs\/preview\/\">latest preview<\/a> 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 \u201c<a href=\"https:\/\/docs.microsoft.com\/en-us\/visualstudio\/ide\/how-to-report-a-problem-with-visual-studio\">Report a Problem<\/a>\u201d or \u201cSuggest a Feature\u201d 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 <a href=\"mailto:cmake@microsoft.com\">cmake@microsoft.com<\/a> with questions as well.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Visual Studio 2019 version 16.1 Preview 2 comes with support for Clang\/LLVM out-of-the-box. Visual Studio has had great tooling for MSVC and GCC for quite a while now. The latest preview brings Clang into the fold. Visual Studio 2019 includes out of the box support for editing, building, and debugging CMake projects with Clang\/LLVM. If [&hellip;]<\/p>\n","protected":false},"author":326,"featured_media":24160,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[563,266,269],"tags":[252],"class_list":["post-24155","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-clang","category-cmake","category-openfolder","tag-cmake"],"acf":[],"blog_post_summary":"<p>Visual Studio 2019 version 16.1 Preview 2 comes with support for Clang\/LLVM out-of-the-box. Visual Studio has had great tooling for MSVC and GCC for quite a while now. The latest preview brings Clang into the fold. Visual Studio 2019 includes out of the box support for editing, building, and debugging CMake projects with Clang\/LLVM. If [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/24155","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/users\/326"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/comments?post=24155"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/24155\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/media\/24160"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/media?parent=24155"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/categories?post=24155"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/tags?post=24155"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}