How to build llvm on windows

Clang/LLVM support in Visual Studio projects

Clang support for both CMake and MSBuild projects is available in Visual Studio 2019.

You can use Visual Studio 2019 version 16.2 and later with Clang to edit, build, and debug C++ Visual Studio projects (MSBuild) that target Windows or Linux.

Install

For best IDE support in Visual Studio, we recommend using the latest Clang compiler tools for Windows. If you don’t already have the tools, you can install them by opening the Visual Studio Installer and choosing C++ Clang tools for Windows under Desktop development with C++ optional components. You may prefer to use an existing Clang installation on your machine; if so, choose the C++ Clang-cl for v142 build tools. optional component.

The Microsoft C++ Standard Library requires at least Clang 8.0.0.

Later versions of Visual Studio provide newer versions of the Clang toolset. The bundled version of Clang gets updated automatically to stay current with updates in the Microsoft implementation of the Standard Library. For example, Visual Studio 2019 version 16.9 includes Clang v11.

Configure a Windows project to use Clang tools

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.

General selected and the Platform Toolset and L L V M (clang c l) options highlighted.» data-linktype=»relative-path»>

If you’re using the Clang tools that are bundled with Visual Studio, no extra steps are required. For Windows projects, Visual Studio by default invokes Clang in clang-cl mode. It links with the Microsoft implementation of the Standard Library. By default, clang-cl.exe is located in %VCINSTALLDIR%\Tools\Llvm\bin\ and %VCINSTALLDIR%\Tools\Llvm\x64\bin\.

If you’re 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. For more information, see Set a custom LLVM location.

Configure a Linux project to use Clang tools

For Linux projects, Visual Studio uses the Clang GCC-compatible frontend. The project properties and nearly all compiler flags are identical

To configure a Visual Studio Linux project to use Clang:

  1. Right-click on the project node in Solution Explorer and choose Properties.
  2. Typically, you should first choose All configurations at the top of the dialog.
  3. Under General >Platform Toolset, choose WSL_Clang_1_0 if you’re using Windows Subsystem for Linux (WSL). Choose Remote_Clang_1_0 if you’re using a remote machine or VM.
  4. Press OK.

General selected and the Platform Toolset and L L V M (clang c l) options highlighted.» data-linktype=»relative-path»>

On Linux, Visual Studio by default uses the first Clang location that it finds in the PATH environment property. If you’re using a custom Clang installation, then either change the value of the LLVMInstallDir property or else enter the path under Project > Properties > Configuration Properties > VC++ DIrectories > Executable Directories. For more information, see Set a custom LLVM location.

Читайте также:  Как установить android с mac os

Set a custom LLVM location

You can set a custom path to LLVM for one or more projects by creating a Directory.build.props file. Then, add 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 use your actual LLVM path):

You can combine this property with a custom LLVM toolset version. For more information, see Set a custom LLVM toolset version.

Set a custom LLVM toolset version

Starting in Visual Studio 2019 version 16.9, you can set a custom toolset version for LLVM. To set this property in a project in Visual Studio:

Open the project’s Property Pages dialog box. For details, see Set C++ compiler and build properties in Visual Studio.

Select the Configuration Properties > General property page.

Modify the Platform Toolset property to LLVM (clang-cl), if it isn’t already set.

Select the Configuration Properties > Advanced property page.

Modify the LLVM Toolset Version property to your preferred version, and then choose OK to save your changes.

The LLVM Toolset Version property only appears when the LLVM platform toolset is selected.

You can set the toolset version for one or more projects by creating a Directory.build.props file. Then, add that file to the root folder of any project. Add it to the root solution folder to apply it to all projects in the solution. The file should look like this (but use your actual LLVM path):

You can also combine this property with a custom LLVM location. For example, your Directory.build.props file could look like:

When you add a Directory.build.props file, the settings appear as the default in the project Property Pages dialog. However, changes to these properties in Visual Studio override the settings in the Directory.build.props file.

Set additional properties, edit, build, and debug

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’re 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 similar to the ones for MSVC. However, some compiler-dependent features such as Edit and Continue aren’t available for Clang configurations. You can set a Clang compiler or linker option that isn’t available in the property pages. Add it manually in the property pages under Configuration Properties > C/C++ (or Linker) > Command Line > Additional Options.

When debugging, you can use breakpoints, memory and data visualization, and most other debugging features.

How to build llvm on windows

LLVM on Microsoft Windows

This repository gathers LLVM code examples coming from various websites and books.
It also includes several batch files for experimenting with the LLVM infrastructure on a Windows machine.

GraalVM, Haskell, Kotlin, Node.js, Scala 3 and TruffleSqueak are other trending topics we are currently monitoring.

Читайте также:  Will all programs work with windows 10

This project depends on the following external software for the Microsoft Windows plaform:

Optionally one may also install the following software:

For instance our development environment looks as follows (April 2021) [5] :

Installation policy
When possible we install software from a Zip archive rather than via a Windows installer. In our case we defined C:\opt\ as the installation directory for optional software tools (in reference to the /opt/ directory on Unix).

This project is organized as follows:

  • directory bin\ contains a batch file and the tools vswhere and pelook.
  • directory docs\ contains several LLVM related papers/articles.
  • directory examples\ contains LLVM code examples (see examples\README.md).
  • directory llvm-8.0.1.src\ contains the LLVM 8 source code distribution.
  • directory llvm-9.0.1.src\ contains the LLVM 9 source code distribution.
  • directory llvm-10.0.1.src\ contains the LLVM 10 source code distribution.
  • directory llvm-11.1.0.src\ contains the LLVM 11 source code distribution.
  • directory llvm-12.0.0rc4.src\ contains the LLVM 12 source code distribution.
  • file BUILD.md describes the build from the source distribution.
  • file README.md is the Markdown document for this page.
  • file RESOURCES.md is the Markdown document presenting external resources.
  • file setenv.bat is the batch script for setting up our environment.

We also define a virtual drive L: in our working environment in order to reduce/hide the real path of our project directory (see article «Windows command prompt limitation» from Microsoft Support).

🔎 We use the Windows external command subst to create virtual drives; for instance:

In the next section we give a brief description of the batch files present in this project.

We distinguish different sets of batch commands:

setenv.bat — This batch command makes external tools such as clang.exe and git.exe directly available from the command prompt (see section Project dependencies).

bin\llvm\build.bat — This batch command generates/installs additional files such as executables, header files, library files, CMake modules not available in LLVM installation directory (in our case C:\opt\LLVM-11.1.0\ ).

setenv.bat

Command setenv is executed once to setup our development environment; it makes external tools such as clang.exe , opt.exe and git.exe directly available from the command prompt:

Important note
Command setenv does not add MSVS CMake and GNU Cmake to the PATH environment variable because of name conflict. We write either %MSVS_CMAKE_HOME%\bin\cmake.exe or %CMAKE_HOME%\bin\cmake.exe .

Command setenv -verbose also displays the tool paths:

llvm-X.Y.Z.src\build.bat

We wrote the batch file build.bat to generate additional Windows binaries not available in the LLVM binary distribution.

It provides the following options and subcommands:

See document BUILD.md for more details.

examples\JITTutorial1\build.bat

See document RESOURCES.md for LLVM related resources.

[1] LLVM version

LLVM versions 8, 9, 10 and 11 are supported. Command setenv searches for version 11 per default; use command setenv -llvm:8 to work with LLVM 8 (idem for LLVM 9).

[2] Visual Studio version

Version 16.5 of Visual Studio 2019 is required to build LLVM 10 while version 16.4 is fine to build LLVM 8 and 9.

[3] Cppcheck installation

The Cppcheck static analysis tool can be installed in two ways on MS Windows, namely:

Below we execute the command pacman -S mingw-w64-x86_64-cppcheck and then check the cppcheck installation :

[4] MSYS2 versus MinGW

We give here three differences between MSYS64 and MingGW-w64:

Читайте также:  Pcs with linux os
Criteria MSYS64 MingGW-w64
Installation size 4.74 GB 614 MB
Version/architecture gcc 10.2 gcc 8.1
Update tool pacman -Syu (1) mingw-get upgrade (2)

Key «XXX» is unknown
One may encounter the MSYS error ‘ key «XXX» is unkown ‘ when running pacman -Syu from the Windows prompt. Simply run the command once from the MingW64 shell (command %MSYS_HOME%\mingw64.exe ) to solve the issue.

2. MinGW-w64 tools:

[5] Downloads

In our case we downloaded the following installation files (see section 1):

Microsoft doesn’t provide an offline installer for VS 2019 but we can follow the following instructions to create a local installer (so called layout cache) for later (re-)installation.

How to Build LLVM and Clang on Windows

I heard about LLVM roughly two years ago from a coworker. It supposed to be this magical compiler that optimizes your code at multiple levels, or passes, including compile-time, link-time, run-time, and “idle-time”. It’s on my to-play-with list and I haven’t really got a chance to get to it till now. Within the last two years things got a lot more interesting. Apparently Apple is one of the main forces behind LLVM and Clang. To be honest, I probably would have delayed it if it wasn’t for Xcode 4 will have LLVM techology integrated in it, plus the renderer project I want to start and the recent presentation I attended etc., etc., anyway. The point is, LLVM is (about to) catching up with the main stream developers. It’s better to learn it now than never!

I’m just assuming absolutely *no one* would ever have a problem to build LLVM and Clang on Linux and Mac, right? I’m not a Windows fanboy, but really like vim and Visual Studio, therefore I develop on Windows whenever I can. I hope that doesn’t offend anyone. In fact, I reallly enjoy using vim commands inside Visual Studio. OK, that will be another post. But let’s focus on the task at hand, build LLVM and Clang on Windows.

It’s surprisingly easy. First, I’d ignore the instruction on LLVM’s page, and rather follow the instruction on Clang’s project page, which is much more concise and will build both LLVM and Clang.

My system: Windows 7 (64 bit), Visual Studio 2010.

Not sure why Clang would ask about svn, but when you run

it might complain that Subversion_SVN_EXECUTABLE and PYTHON_EXECUTABLE are not found. You just set them as follows:

The rest is fairly straightforward. Currently Clang doesn’t work with Visual C++ header files such as iostream. STLport doesn’t work either. However I was able to compile simple C++ code without including the STL headers.

I have been a computer graphics enthusiast and researcher for many years. My interests has broadened to include mobile, high performance computing, machine learning, and computer vision.

Comments

I think I am seeing the same ‘doesn’t work with IOStreams’ that you speak of, do you know if there is a clang bug on this? I tried their Bugzilla site, but didn’t find any luck. It is somewhat opaque to me where these symbols are coming from, but I see unresolved externals for things like:

error LNK2019: unresolved external symbol __ZSt4cout referenced in function _main

Оцените статью