{"id":24522,"date":"2019-07-11T12:16:47","date_gmt":"2019-07-11T12:16:47","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/cppblog\/?p=24522"},"modified":"2019-07-11T15:45:31","modified_gmt":"2019-07-11T15:45:31","slug":"clang-llvm-support-for-msbuild-projects","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/cppblog\/clang-llvm-support-for-msbuild-projects\/","title":{"rendered":"Clang\/LLVM Support for MSBuild Projects"},"content":{"rendered":"<p>Visual Studio 2019 version 16.2 Preview 3 includes built-in Clang\/LLVM support for MSBuild projects. In our last release, <a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/visual-studio-cmake-support-clang-llvm-cmake-3-14-vcpkg-and-performance-improvements\/\">we announced support for Clang\/LLVM for CMake<\/a>. In the latest Preview of Visual Studio, we have extended that support to also include MSBuild projects. While in most cases we recommend using the MSVC compiler, we are committed to making Visual Studio one of the most comprehensive IDEs on Windows. You may want to use Clang instead if you are developing cross platform code, especially if it already depends on Clang or GCC extensions. You can now use Clang\/LLVM to target both Windows and Linux using MSBuild just like you can with CMake projects. We\u2019ve also updated our included version of Clang to 8.0.0. Please <a href=\"https:\/\/visualstudio.microsoft.com\/vs\/preview\/\">download the latest Preview<\/a> to try it out and let us know how it works.<\/p>\n<h3>Installing the Clang Tools for Visual Studio<\/h3>\n<p>You can install the Clang tools for Windows by selecting \u201cC++ Clang Tools for Windows\u201d as part of the \u201cDesktop development with C++\u201d workload. It is not installed by default, but if you have installed it before, Clang will automatically be updated to 8.0.0 when you install the latest Preview.<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-24523\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2019\/07\/Installer-Annotated.png\" alt=\"Install the \u201cC++ Clang tools for Windows\u201d component with the \u201cDesktop development with C++\u201d workload.\" width=\"1937\" height=\"1082\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2019\/07\/Installer-Annotated.png 1937w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2019\/07\/Installer-Annotated-300x168.png 300w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2019\/07\/Installer-Annotated-768x429.png 768w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2019\/07\/Installer-Annotated-1024x572.png 1024w\" sizes=\"(max-width: 1937px) 100vw, 1937px\" \/><\/p>\n<p>If you want to use your own Clang compiler with Windows instead of the bundled one, you can do that too. Navigate to \u201cIndividual Components\u201d and select \u201cC++ Clang-cl for v142 build tools.\u201d You will only be able to use recent versions of Clang (8.0.0 or later) with the Microsoft STL though. We strongly recommend using the bundled compiler as it will be kept up to date as the STL is updated.<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-24524\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2019\/07\/Individual-Components-Annotated.png\" alt=\"Or just install the tooling with \u201cC++ Clang-cl for v142 build tools\u201d under \u201cIndividual Components.\u201d\" width=\"1937\" height=\"1082\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2019\/07\/Individual-Components-Annotated.png 1937w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2019\/07\/Individual-Components-Annotated-300x168.png 300w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2019\/07\/Individual-Components-Annotated-768x429.png 768w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2019\/07\/Individual-Components-Annotated-1024x572.png 1024w\" sizes=\"(max-width: 1937px) 100vw, 1937px\" \/><\/p>\n<p>To use Clang with Linux projects, just install the \u201cLinux development\u201d workload. You won\u2019t need to select any more components. The remote machine or WSL will need to have Clang installed. Just install Clang from your distribution\u2019s package manager or from <a href=\"https:\/\/releases.llvm.org\/download.html\">LLVM\u2019s download page<\/a>.<\/p>\n<h3>Use Clang with Windows MSBuild Projects<\/h3>\n<p>You can use Clang with most MSBuild projects that target Windows. To get started, create a new C++ project or open an existing one. Then, you can change the platform toolset to \u201cLLVM (clang-cl)\u201d:<img decoding=\"async\" class=\"alignnone size-full wp-image-24525\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2019\/07\/Clang-cl-Platform-Toolset.png\" alt=\"Select the \u201cLLVM (clang-cl)\u201d Platform Toolset under Configuration Properties &gt; General.\" width=\"1253\" height=\"898\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2019\/07\/Clang-cl-Platform-Toolset.png 1253w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2019\/07\/Clang-cl-Platform-Toolset-300x215.png 300w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2019\/07\/Clang-cl-Platform-Toolset-768x550.png 768w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2019\/07\/Clang-cl-Platform-Toolset-1024x734.png 1024w\" sizes=\"(max-width: 1253px) 100vw, 1253px\" \/><\/p>\n<p>If this toolset doesn\u2019t appear, it likely isn\u2019t installed \u2013 see above for installation instructions.<\/p>\n<p>Visual Studio uses the clang-cl frontend with MSBuild on Windows so the properties for Clang will be the same as MSVC based projects. Some compiler options are not supported by clang-cl (e.g. Just My Code) and will be not be shown in the Property Pages when you are using Clang.<\/p>\n<h3>Use Clang with Linux MSBuild Projects<\/h3>\n<p>Using Clang with Linux projects is also as simple as selecting the appropriate platform toolset. For Linux projects, there are two toolsets to choose from. One for using Clang with a WSL instance on the local machine and another for using Clang on a remote machine:<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-24526\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2019\/07\/Remote-Clang-Platform-Toolset.png\" alt=\"\" width=\"1253\" height=\"898\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2019\/07\/Remote-Clang-Platform-Toolset.png 1253w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2019\/07\/Remote-Clang-Platform-Toolset-300x215.png 300w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2019\/07\/Remote-Clang-Platform-Toolset-768x550.png 768w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2019\/07\/Remote-Clang-Platform-Toolset-1024x734.png 1024w\" sizes=\"(max-width: 1253px) 100vw, 1253px\" \/><\/p>\n<p>For Linux projects, Visual Studio uses the Clang GCC-compatible frontend. The project properties and nearly all compiler flags are identical.<\/p>\n<h3>Custom Clang Installations and Compiler Arguments<\/h3>\n<p>You can also use a custom installation of Clang. On Windows, by default, the built-in version of Clang from the installer will always be used. On Linux, the first installation of Clang found on the PATH will be used. However, you can override this behavior on either platform by setting defining a property in your project file:<\/p>\n<pre title=\"LLVMInstallDir\" class=\"lang:xhtml decode:true \">&lt;LLVMInstallDir&gt;PATH_TO_LLVM&lt;\/LLVMInstallDir&gt;<\/pre>\n<p>To do this, you will need to unload your project and edit it. You can add this to any project configurations that you would like to use your custom installation of Clang. Keep in mind, the Microsoft STL is only compatible with very recent versions of Clang: 8.0.0 as of this post.<\/p>\n<p>If you need to use a Clang compile or link flag that isn\u2019t supported by the project property pages, you can do that in the project properties under Configuration Properties &gt; C\/C++ or Linker &gt; Command Line. Consider opening a feedback ticket if you find yourself using a particular option this way frequently. Based on demand, we may add it to the property pages.<\/p>\n<h3>Send us Feedback<\/h3>\n<p>Your feedback is a critical part of ensuring that we can deliver the best experience.\u00a0 We would love to know how\u00a0<a href=\"https:\/\/www.visualstudio.com\/vs\/preview\/\">Visual Studio 2019 version 16.2 Preview 3<\/a>\u00a0is working for you.\u00a0If you find any issues or have a suggestion, the best way to reach out to us is to\u00a0<a href=\"https:\/\/docs.microsoft.com\/en-us\/visualstudio\/ide\/how-to-report-a-problem-with-visual-studio\">Report a Problem<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Visual Studio 2019 version 16.2 Preview 3 includes built-in Clang\/LLVM support for MSBuild projects. In our last release, we announced support for Clang\/LLVM for CMake. In the latest Preview of Visual Studio, we have extended that support to also include MSBuild projects. While in most cases we recommend using the MSVC compiler, we are committed [&hellip;]<\/p>\n","protected":false},"author":326,"featured_media":24524,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[270],"tags":[255,257],"class_list":["post-24522","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-announcement","tag-clang","tag-llvm"],"acf":[],"blog_post_summary":"<p>Visual Studio 2019 version 16.2 Preview 3 includes built-in Clang\/LLVM support for MSBuild projects. In our last release, we announced support for Clang\/LLVM for CMake. In the latest Preview of Visual Studio, we have extended that support to also include MSBuild projects. While in most cases we recommend using the MSVC compiler, we are committed [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/24522","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=24522"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/24522\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/media\/24524"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/media?parent=24522"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/categories?post=24522"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/tags?post=24522"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}