.Heindl Solutions - Experiments with clang for Visual Studio 2015 Update 1

Experiments with clang for Visual Studio 2015 Update 1

2015-12-21 by Andreas Heindl



Microsoft Visual Studio 2015 Update 1 ships with a special version of clang. Microsoft names it Clang with Microsoft CodeGen. It uses the clang parsing backend together with the traditional Microsoft cl code generator and optimizer backend.

To use the compiler from the command line (cmd.exe), setup Visual Studio 2015 environment as follows:

@echo off
REM setup VS2015 environment
call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools\VsDevCmd.bat"
 
REM add clang to your PATH
SET PATH=C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\Clang 3.7\bin\x86;%PATH%
 
REM check: Windows should be able to find clang executable:
where clang
REM output will be:
REM   C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\Clang 3.7\bin\x86\clang.exe
 
clang --version
REM output will be:
REM   clang with Microsoft CodeGen version 3.7.0
REM   Provided as - is without support
REM   Target: i686-pc-windows-msvc
REM   Thread model: posix

Maybe you have to adapt the paths for your specific computer configuration.

I recommend saving the file e.g. as clang_vs2015.bat

You can then compile e.g. using clang test_sum.cpp -O3 -DNDEBUG -d2Qpar-report:1 -d2Qpar -d2Qvec-report:2 test_sum_clang.exe

In this example, this command line passes arguments to the Microsoft Compiler Frontend via -d2.