如何在 MSBuild 中使用 Clang 编译器? [英] How to use Clang compiler with MSBuild?

查看:23
本文介绍了如何在 MSBuild 中使用 Clang 编译器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用通常在 Windows 上使用 Microsoft C++ 编译的几个项目,然后使用 clang 编译它们.

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

从好的方面来说,存在 clang-cl.exe,它旨在替代 cl.exe.但是,即使我将clang-cl.exe作为cl.exe复制到当前目录,msbuild在某些情况下仍然会调用微软的cl.exe.

On the upside, there exists clang-cl.exe which is designed to be a drop-in replacement for cl.exe. However, even when I copy clang-cl.exe into the current directory as cl.exe, msbuild still in some cases calls Microsoft's cl.exe.

有没有办法告诉 msbuild '这里,在执行任务 CL 时,使用这个 cl.exe 而不是通常的那个'?msbuild 的命令行选项不包含任何明显的方向.

Is there a way to tell msbuild 'here, when executing Task CL, use this cl.exe instead of the usual one'? msbuild's command line options don't contain anything obvious in that direction.

另外,有没有办法告诉它在不更改项目文件的情况下为 cl 提供或覆盖命令行参数?

Also, is there a way to tell it to supply or override command line parameters for cl without changing the project file?

推荐答案

这很容易从命令行或项目文件中完成.您需要配置的属性是$(CLToolExe)$(CLToolPath).

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

从命令行:

msbuild MyProj.vcxproj /p:CLToolExe=clang-cl.exe /p:CLToolPath=c:whateverpath	o	he	ool

或者,在您的 .vcxproj 文件中:

Alternatively, inside your .vcxproj file:

<PropertyGroup>
  <CLToolExe>clang-cl.exe</CLToolExe>
  <CLToolPath>c:whateverpath	o	he	ool</CLToolPath>
</PropertyGroup>

如果你是在你的.vcxproj文件中直接调用任务CL,而不是仅仅依赖公共目标,只需设置CL任务的相应参数ToolExeToolPath.

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.

这篇关于如何在 MSBuild 中使用 Clang 编译器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆