0

I'm working on a Visual Studio project that uses cl.exe as its compiler. However, I need to use a different compiler without having to modify the project files directly.

I've tried playing around with different environment variables to no avail. Does anyone know of a way to use a different compiler without messing with the project files? Maybe a specific environment variable or command line option that I'm not aware of?

If anyone has any advice or guidance on this, I'd really appreciate it. Thanks!

Daniel Stephens
  • 2,371
  • 8
  • 34
  • 86
  • 1
    Assuming the project file was generated by Visual Studio, cl.exe is invoked indirectly via the [CL task](https://learn.microsoft.com/en-us/visualstudio/msbuild/cl-task?view=vs-2022). You could create a custom CL task and override the standard task. See the note about overriding in the [UsingTask element](https://learn.microsoft.com/en-us/visualstudio/msbuild/usingtask-element-msbuild?view=vs-2022) documentation. I don't know how practical that is for you. – Jonathan Dodds Feb 23 '23 at 02:33
  • Thanks! I will look into it. Surprised there is no counter option for `CC` and `CXX` on Unix – Daniel Stephens Feb 23 '23 at 18:00
  • 1
    MSBuild was Windows-only when first released and for most of its history. It was taken cross-platform to support .Net Core/.Net. `cl.exe` supports managed C++. Another approach would be to create an MSBuild "[Project SDK](https://learn.microsoft.com/en-us/dotnet/core/project-sdk/overview)" specific to the compiler you want to use. But this wouldn't be a drop-in replacement. The project file would change. – Jonathan Dodds Feb 24 '23 at 01:19
  • If it's really just changing the executable (i.e. when yours has compatible commandline arguments and beahvior) then this: https://stackoverflow.com/questions/45835043/how-to-override-compile-command-of-visual-studio-2017-community – stijn Mar 02 '23 at 14:38

0 Answers0