LLVM clang 4.0 and higher in Visual Studio 2017

the official build of LLVM 4.0 for Windows integrates with Visual Studio until Visual Studio 2015. Unfortunately, it still does not support Visual Studio 2017.

When you try to set the Platform Toolet project to LLVM-vs2014 , an error message appears.

Do you know how this works?


Update

In 2018, LLVM 6.0 did not officially support integration with Visual Studio 2017 (version 15.XX), only with the Visual Studio 2015 toolkit (version 14.XX).

+5
source share
5 answers

Finally, I found a brilliant rehearsal of GitHub with the necessary MSBuild platform tools that LLVM clang integrates in Visual Studio 2017 . Following the instructions in the README file, you will receive two new platform tools LLVM-vs2017 and LLVM-vs2017_xp . The problem is resolved.

0
source

This requires some msbuild goals that come only with the C ++ v140 toolkit, and VS 2017 installs the v141 toolkit by default. If you open the VS 2017 installer, check the box for the v140 toolkit and install it, then the C ++ msbuild targets will be available, and everything will work.

+7
source

LLVM / Clang now has an updated patch that allows you to use it with VS2017. But they still do not support VS2017 directly. I asked the LLVM developers mailing list to update their support for VS2017, so I hope they do. If they listen to what I said.

+1
source

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

ie, lld-link / DEBUG: GHASH; clang-cl -mllvm -emit-codeview-ghash-section flag for clang-cl.

This is a three-step process.

  • Install latest llvm
  • Update toolset.props, toolset.targets in VS to support the latest clang
  • Choose a new toolkit to create your C / C ++ project or other lang

Starting with the Visual Studio 2017 15.4.5 update, the Microsoft “experimental” Clang C2 no longer works. Thus, the above fixes are needed to use clang to compile code that has full PDB (not only limited to CodeView / Z7), debugging. It also now becomes a more comprehensive cross-platform build portability test kit, as you can create and debug PDBs for windows using all LLVM components from the front end of the clang compiler to the LLVM backend and LLVM linker.

Cheers, David

+1
source

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

Look at "Try it!" section:

If you are already using clang-cl and lld-link on Windows today, you can try this. Two flags are needed for this, one for the compiler and one for the linker: To enable the compiler to select the .debug $ H section, you need to pass the undocumented flag -mllvm -emit-codeview-ghash-section to clang-cl (this flag should go in the future as soon as it is considered stable and good enough for inclusion by default). To tell lld-link this information, you need to pass /DEBUG:GHASH to lld.

You just need to pass the -mllvm -emit-codeview-ghash-section flags in your C ++ projects “Command Line: Advanced Options” or put 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 when you add these cli parameters that you specify clang to emit debug information, lld (aka lld-link ) will understand and use to create fully populated PDB files. Unlimited, which were made before the drops of LLVM 7.0 dated January 09, 2018.

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

pps, I also included the Microsoft ARM and ARM64 compilers to create my own Windows-10-ARM applications (and not UWP-modern harvesters). But so far, I have not done enough work in the clang sources to correctly configure something similar for ARM to what -m32 and -m64 do for Intel code-gen.

See the following articles:

0
source

Source: https://habr.com/ru/post/1266839/


All Articles