8

The official LLVM 4.0 build for Windows integrates with Visual Studio up to Visual Studio 2015. Unfortunately it still doesn't support Visual Studio 2017.

When you try to set the Platform Toolset of a project to LLVM-vs2014, it pops up an error.

Do you know any way to make it work?


Update

In 2018, LLVM 6.0 officially still doesn't support integration with Visual Studio 2017 (version 15.X.X), only with the Visual Studio 2015 (version 14.X.X) toolset.

Royi
  • 4,640
  • 6
  • 46
  • 64
plasmacel
  • 8,183
  • 7
  • 53
  • 101

7 Answers7

10

It requires some msbuild targets that only ship with the C++ v140 toolset, and VS 2017 only installs the v141 toolset by default. If you open the VS 2017 installer, find the checkbox for the v140 toolset and install that then the right C++ msbuild targets will be available and the thing will work.

keith
  • 5,122
  • 3
  • 21
  • 50
  • Yes it would be good of them to support v141 without the need for v140 :-) – keith May 17 '17 at 14:45
  • 4
    Would also be good of them to change the name from LLVM-vs2014! – keith May 17 '17 at 14:47
  • This sounds subject to change. Is there something official we can look at that will give us current information? I can't _find the checkbox for the v140 toolset_; I would look closer but if it now does not exist then I won't. – Sam Hobbs Dec 02 '17 at 19:35
  • 2
    @user34660, there's a tab called "Individual Components", it's still there on that tab! – keith Dec 02 '17 at 20:35
  • @keith The problem is finally solved. See my own answer. – plasmacel Mar 26 '18 at 22:31
8

Finally, I found a brilliant GitHub repo with the required MSBuild platform toolsets which integrates LLVM clang 5.0.0 into Visual Studio 2017. After following the instructions of the README file, you will have two new platform toolsets LLVM-vs2017 and LLVM-vs2017_xp. Problem solved.

Update

I made a fork which is updated for LLVM 6.0.0 and provides better integration by providing include and library paths of LLVM/clang.

Thanks to Royi, who realized that the original .prop files are explicitly tailored for LLVM 5.0 and it misses adding the proper lib ( $(LLVMInstallDir)\lib) and include ($(LLVMInstallDir)\lib\clang\6.0.0\include) folders.

Royi
  • 4,640
  • 6
  • 46
  • 64
plasmacel
  • 8,183
  • 7
  • 53
  • 101
  • Will it create files which are compatible with Windows yet are optimized by Clang? For instance, will I have updated OpenMP support? – Royi May 09 '18 at 20:40
  • @Royi Yes. Not only optimized by clang, but completely compiled by clang. However if you want OpenMP support, you will need `libomp` and enable it by a compiler switch. See https://openmp.llvm.org. – plasmacel May 12 '18 at 11:34
  • @Royi In newer LLVM versions it is enabled by default, yeah. However, unfortunately, the latest LLVM binary distribution doesn't include `libomp`. So maybe you have to build it on your own. – plasmacel May 12 '18 at 11:49
  • @Royi If you mean the "Pre-Built Binaries" distribution, then no. Unfortunately, lately they removed `libomp` from the binary distribution. However if you download the sources, you can build `libomp` yourself. – plasmacel May 12 '18 at 14:45
  • @Royi As I remember the last LLVM version where they included `libomp` in the binary distribution was **LLVM 5.0**. You can also download previous versions on the linked download page. – plasmacel May 12 '18 at 14:47
  • 1
    @Royi You can also try to copy `libomp.lib` and `libomp.dll` from a binary distribution which includes them to the binary distribution of the newest version. You have to simply put them into the `bin` folder. – plasmacel May 12 '18 at 15:11
  • 1
    Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/170911/discussion-between-plasmacel-and-royi). – plasmacel May 12 '18 at 16:40
  • 1
    @Royi I successfully built the OpenMP libraries for LLVM 6.0 using Visual Studio 2017 for 32bit and 64bit targets. – plasmacel May 12 '18 at 18:56
  • 1
    @Royi Yeah, I built the whole LLVM 6.0.1 for Windows, which includes all of its components (note that the official distribution on LLVM's website lacks about 75% of LLVM). – plasmacel Aug 18 '18 at 21:07
  • 1
    @Royi Get it here: https://drive.google.com/file/d/1-RIWatkOTmk_uO-81vJH1Bty13B4oK03/view?usp=sharing – plasmacel Aug 18 '18 at 21:12
  • Is there a way to get only OpenMP? When you say you build, is this the build for Windows (Namely `cl` like?) Or the original Clang? I meant adding only OpenMP to the repository. – Royi Aug 18 '18 at 21:16
  • 1
    @Royi LLVM is inherently a cross-compiler. `clang` is just a compiler frontend for it. `clang-cl` is just a shortcut for `clang --driver-mode=cl`, so you can use clang as `cl` on **any** supported platform, not just Windows. So if you need, it is "`cl` like" on any platform, you can build for Windows on any platform. I shared the Windows binary distribution with you. If you only need libomp, then locate its related files. – plasmacel Aug 18 '18 at 21:21
  • 1
    @Royi Actually it is a Windows x64 build, so you cannot use it with 32-bit targets. I don't support 32-bit targets anymore. – plasmacel Aug 18 '18 at 21:28
  • plasmacel, Any chance you have Clang with OpenMP support in version 7.1 and 8.0? – Royi Apr 22 '19 at 05:58
4

The LLVM project now explicitly supports Visual Studio 2017 via https://marketplace.visualstudio.com/items?itemName=LLVMExtensions.llvm-toolchain

thakis
  • 5,405
  • 1
  • 33
  • 33
2

I have figured out how to integrate LLVM Clang 7.0 with Visual Studio 2017 update 15.5.6. v1913 with full support for PDB based debugging using the latest LLVM builds.

i.e., lld-link /DEBUG:GHASH; clang-cl -mllvm -emit-codeview-ghash-section flag to clang-cl.

It is a three step process.

  1. Install latest llvm
  2. Update the toolset.props, toolset.targets in VS to support latest clang
  3. Select the new toolset to use for building your C/C++ or other lang project

As of Visual Studio 2017 update 15.4.5 the Microsoft "experimental" Clang C2 no longer works. Thus, the above fixes are necessary to use clang to compile code that has full PDB (not just CodeView /Z7 limited) debuggability. This also now becomes a more complete suite for portability testing cross-platform builds since you can build and PDB debug for windows using all LLVM components from the clang compiler front end to the LLVM codegen backend and LLVM linker.

Cheers, David

smallscript
  • 643
  • 7
  • 13
2

I'm a newbie with the LLVM technology and I'm using a Visual Studio extension, Clang Power Tools. They have a settings page from where you can install LLVM (all versions >= 4.0). After that you are free to apply clang compile or tidy with code modernization(this is what I appreciate the most) by using the extension buttons from VS toolbar. In this way you don't need to configure anything.

Update

Open the extension settings and select the LLVM page from the top. On the LLVM page, you'll see all the supported LLVM versions and at the right of each version the install button. Install any version you need. On the bottom of the page is a dropdown that allows you to select what version to use in case you installed multiple versions.

The feature is explained step by step in this blog post

  • however links may answer the question, they can become invalid in future, consider adding some quotations to your answer and then refer to blog posts. – zhisme Dec 09 '20 at 12:55
1

LLVM/Clang now has an updated patch that allows you to use it with VS2017. But they still don't directly support VS2017. I asked on the LLVM developer mailing list for them to update their support for VS2017, so hopefully they'll do it. If they listen to what I said.

0

Check out January 09, 2018 http://planet.clang.org/

Look at the "Try it out!" section:

If you're already using clang-cl and lld-link on Windows today, you can try this out. There are two flags needed to enable this, one for the compiler and one for the linker: To enable the emission of a .debug$H section by the compiler, you will need to pass the undocumented -mllvm -emit-codeview-ghash-section flag to clang-cl (this flag should go away in the future, once this is considered stable and good enough to be turned on by default). To tell lld-link to use this information, you will need to pass the /DEBUG:GHASH to lld.

You just need to pass the -mllvm -emit-codeview-ghash-section flags in either your c++ projects "Command Line:Additional Options" area, or place them directly in the "toolset.props" file that you created in C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\VC\VCTargets\Platforms\Win32\PlatformToolsets\LLVM-vs2017 or C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\VC\VCTargets\Platforms\x64\PlatformToolsets\LLVM-vs2017.

The key is that in adding those cli options you're telling clang to emit debug information that the lld (aka lld-link) will understand and use to produce fully populated PDB files. Not the limited ones it made prior to the Jan 09, 2018 drops of LLVM 7.0.

toolset.targets: (any version)

<Project ToolsVersion="14.1" 
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Import Project="$(VCTargetsPath)\Microsoft.CppCommon.targets" />
</Project>

toolset.props: (Win32 version)

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">  
  <Import Project="$(VCTargetsPath)\Platforms\$(Platform)\PlatformToolsets\v141\Microsoft.Cpp.$(Platform).v141.props" Condition="Exists('$(VCTargetsPath)\Platforms\$(Platform)\PlatformToolsets\v141\Microsoft.Cpp.$(Platform).v141.props')"/>
  <Import Project="$(VCTargetsPath)\Platforms\$(Platform)\PlatformToolsets\v141\Toolset.props" Condition="Exists('$(VCTargetsPath)\Platforms\$(Platform)\PlatformToolsets\v141\Toolset.props')"/>

  <PropertyGroup>
    <LLVMInstallDir>$(Registry:HKEY_LOCAL_MACHINE\SOFTWARE\LLVM\LLVM)</LLVMInstallDir>
    <LLVMInstallDir Condition="'$(LLVMInstallDir)' == ''">$(Registry:HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\LLVM\LLVM)</LLVMInstallDir>
    <ExecutablePath>$(LLVMInstallDir)\msbuild-bin;$(ExecutablePath)</ExecutablePath>
    <LibraryPath>$(LLVMInstallDir)\lib\clang\7.0\lib\windows;$(LibraryPath)</LibraryPath>
  </PropertyGroup>

  <ItemDefinitionGroup>
    <ClCompile>
      <!-- remove the implicit vcxxx.pdb path to avoid rebuilds every time as clang-cl only supports /Z7 -->
      <ProgramDataBaseFileName></ProgramDataBaseFileName>
      <!-- Set the value of _MSC_VER to claim for compatibility -->
      <AdditionalOptions>-m32 -fmsc-version=1913 %(AdditionalOptions)</AdditionalOptions>
    </ClCompile>
  </ItemDefinitionGroup>
</Project>

For x64, change -m32 to -m64

p.p.s., I have also enabled Microsofts ARM and ARM64 compilers for building native Windows-10-ARM apps (not UWP modern-com-junk). But, as yet, I have not done enough digging through the clang sources to properly configure something similar for ARM to what -m32 and -m64 do for Intel code-gen.

See these articles:

smallscript
  • 643
  • 7
  • 13
  • It seems that `-mllvm -emit-codeview-ghash-section` become unrecognized option in clang 8.0 as of SVN r347735 (29 November 2018) https://llvm.org/builds/ . While `lld`s option `/DEBUG:GHASH` still produces the .pdb file. – sandthorn Dec 01 '18 at 04:17