How to use Clang compiler with MSBuild?

后端 未结 2 825
花落未央
花落未央 2020-12-06 12:22

I\'m trying to take a couple of projects normally compiled on Windows with Microsoft C++ and compile them with clang instead.

On the upside, there exists clang-cl.ex

相关标签:
2条回答
  • 2020-12-06 12:22

    Since Visual Studio 2019 16.2, Microsoft provide an integration of MSbuild and ClangCl. So this can be achieved by:

    • Installing the “C++ Clang Tools for Windows” component
    • Choosing the "LLVM (clang-cl)” toolset in the IDE

    Microsoft's blog post has more information on this: https://devblogs.microsoft.com/cppblog/clang-llvm-support-for-msbuild-projects/

    0 讨论(0)
  • 2020-12-06 12:39

    This is easy to do from either command line or project file. The properties you need to configure are $(CLToolExe) and $(CLToolPath).

    From the command line:

    msbuild MyProj.vcxproj /p:CLToolExe=clang-cl.exe /p:CLToolPath=c:\whatever\path\to\the\tool
    

    Alternatively, inside your .vcxproj file:

    <PropertyGroup>
      <CLToolExe>clang-cl.exe</CLToolExe>
      <CLToolPath>c:\whatever\path\to\the\tool</CLToolPath>
    </PropertyGroup>
    

    If you are calling task CL directly inside your .vcxproj file, as opposed to just relying on common targets, just set corresponding parameters ToolExe and ToolPath of the CL task.

    0 讨论(0)
提交回复
热议问题