Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
673 views
in Technique[技术] by (71.8m points)

visual studio - How to use Clang compiler with MSBuild?

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.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.

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.

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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:whateverpathoheool

Alternatively, inside your .vcxproj file:

<PropertyGroup>
  <CLToolExe>clang-cl.exe</CLToolExe>
  <CLToolPath>c:whateverpathoheool</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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...