Skip to content

Commit e354c42

Browse files
authored
Merge pull request #2256 from mikeblome/mb-clang-msbuild
new topic and images for clang with msbuild
2 parents a38330a + b6ca1ab commit e354c42

6 files changed

Lines changed: 75 additions & 2 deletions

File tree

docs/build/clang-support-cmake.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: "Clang/LLVM support in Visual Studio CMake projects"
33
ms.date: "07/01/2019"
44
ms.description: "Configure a CMake project in Visual Studio to use the Clang/LLVM toolchain."
5-
helpviewer_keywords: ["Clang support for C++"]
5+
helpviewer_keywords: ["Clang support for C++ CMake projects"]
66
---
77

88
# Clang/LLVM support in Visual Studio CMake projects
@@ -23,7 +23,7 @@ You can use Visual Studio with Clang to edit and debug C++ CMake projects that t
2323

2424
## Install
2525

26-
For best IDE support in Visual Studio, we recommend using the latest Clang compiler tools for Windows. If you don't already have those, you can install them by opening the Visual Studio Installer and choosing **Clang compiler for Windows** under **Desktop development with C++** optional components.
26+
For best IDE support in Visual Studio, we recommend using the latest Clang compiler tools for Windows. If you don't already have those, you can install them by opening the Visual Studio Installer and choosing **C++ Clang compiler for Windows** under **Desktop development with C++** optional components. When using a custom Clang installation, check the **C++ Clang-cl for v142 build tools** component.
2727

2828
![Clang component installation](media/clang-install-vs2019.png)
2929

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
---
2+
title: "Clang/LLVM support in Visual Studio Visual Studio projects"
3+
ms.date: "08/30/2019"
4+
ms.description: "Configure a Visual Studio MSBuild project to use the Clang/LLVM toolchain."
5+
helpviewer_keywords: ["Clang support for C++ MSBuild projects"]
6+
---
7+
8+
# Clang/LLVM support in Visual Studio projects
9+
10+
::: moniker range="<=vs-2017"
11+
12+
Clang support for both CMake and MSBuild projects is available in Visual Studio 2019.
13+
14+
::: moniker-end
15+
16+
::: moniker range="vs-2019"
17+
18+
You can use Visual Studio 2019 version 16.2 with Clang to edit, build, and debug C++ Visual Studio projects (MSBuild) that target Windows or Linux.
19+
20+
## Install
21+
22+
For best IDE support in Visual Studio, we recommend using the latest Clang compiler tools for Windows. If you don't already have those, you can install them by opening the Visual Studio Installer and choosing **C++ Clang tools for Windows** under **Desktop development with C++** optional components. If you prefer to use an existing Clang installation on your machine, choose the **C++ Clang-cl for v142 build tools.** optional component. The Microsoft C++ Standard Library currently requires at least Clang 8.0.0; the bundled version of Clang will automatically be updated to stay current with updates in the Microsoft implementation of the Standard Library.
23+
24+
![Clang component installation](media/clang-install-vs2019.png)
25+
26+
## Configure a Windows project to use Clang tools
27+
28+
To configure a Visual Studio project to use clang, right-click on the project node in **Solution Explorer** and choose **Properties**. Typically, you should first choose **All configurations** at the top of the dialog. Then, under **General** > **Platform Toolset**, choose **LLVM (clang-cl)** and then **OK**.
29+
30+
![Clang component installation](media/clang-msbuild-prop-page.png)
31+
32+
If you are using the Clang tools that are bundled with Visual Studio, no additional steps are required. For Windows projects, Visual Studio by default invokes Clang in [clang-cl](https://llvm.org/devmtg/2014-04/PDFs/Talks/clang-cl.pdf) mode and links with the Microsoft implementation of the Standard Library. By default, **clang-cl.exe** is located in `C:\Program Files (x86)\Microsoft Visual Studio\2019\Common7\IDE\CommonExtensions\Microsoft\Llvm\bin`.
33+
34+
If you are using a custom Clang installation, you can either modify **Project** > **Properties** > **VC++ DIrectories** > **Configuration Properties** > **Executable Directories** by adding the custom Clang installation root as the first directory there, or change the value of the `LLVMInstallDir` property. See [Set a custom LLVM location](#custom_llvm_location) for more information.
35+
36+
## Configure a Linux project to use Clang tools
37+
38+
For Linux projects, Visual Studio uses the Clang GCC-compatible frontend. The project properties and nearly all compiler flags are identical
39+
40+
To configure a Visual Studio Linux project to use Clang:
41+
42+
1. Right-click on the project node in **Solution Explorer** and choose **Properties**.
43+
1. Typically, you should first choose **All configurations** at the top of the dialog.
44+
1. Under **General** > **Platform Toolset**, choose **WSL_Clang_1_0** if you are using Windows Subsystem for Linux, or **Remote_Clang_1_0** if you are using a remote machine or VM.
45+
1. Press **OK**.
46+
47+
![Clang component installation](media/clang-msbuild-prop-page.png)
48+
49+
On Linux, Visual Studio by default uses the first Clang location that it encounters in the PATH environment property. If you are using a custom Clang installation, then you must change the value of the `LLVMInstallDir` property or else substitute a path under **Project** > **Properties** > **VC++ DIrectories** > **Configuration Properties** > **Executable Directories**. See [Set a custom LLVM location](#custom_llvm_location) for more information.
50+
51+
## <a name="custom_llvm_location"></a> Set a custom LLVM location
52+
53+
You can set a custom path for LLVM for one or more projects by creating a *Directory.build.props* file and adding that file to the root folder of any project. You can add it to the root solution folder to apply it to all projects in the solution. The file should look like this (but substitute your actual path):
54+
55+
```xml
56+
<Project>
57+
<PropertyGroup>
58+
<LLVMInstallDir>c:\MyLLVMRootDir</LLVMInstallDir>
59+
</PropertyGroup>
60+
</Project>
61+
```
62+
63+
## Set additional properties, edit, build, and debug
64+
65+
After you have set up a Clang configuration, right-click again on the project node and choose **Reload project**. You can now build and debug the project using the Clang tools. Visual Studio detects that you are using the Clang compiler and provides IntelliSense, highlighting, navigation, and other editing features. Errors and warnings are displayed in the **Output Window**. The project property pages for a Clang configuration are very similar to those for MSVC, although some compiler-dependent features such as Edit and Continue are not available for Clang configurations. To set a Clang compiler or linker option that is not available in the property pages, you can add it manually in the property pages under **Configuration Properties** > **C/C++ (or Linker)** > **Command Line** > **Additional Options**.
66+
67+
When debugging, you can use breakpoints, memory and data visualization, and most other debugging features.
68+
69+
![Clang debugging](media/clang-debug-msbuild.png)
70+
71+
::: moniker-end
34.9 KB
Loading
-20.2 KB
Loading
26.4 KB
Loading

docs/toc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@
5858
href: build/project-property-inheritance.md
5959
- name: Modify properties and targets without changing the project file
6060
href: build/modify-project-properties-without-changing-project-file.md
61+
- name: Clang/LLVM in Visual Studio projects (MSBuild)
62+
href: build/clang-support-msbuild.md
6163
- name: Reference libraries and components at build time
6264
href: build/adding-references-in-visual-cpp-projects.md
6365
- name: Organize project output files

0 commit comments

Comments
 (0)