June 10th, 2011  »   »  40 Comments

A Visual Studio AddIn that lets users play with the Clang C/C++ compiler from within the VS IDE. Designed to translate MSVC C/C++ compiler options into arguments that Clang understands while retaining and executing the rest of the build pipeline.

Clang Menu

Simply load a project and choose Rebuild from the Clang menu. If you’re lucky, you will end up with a functioning executable; if not, the plug-in verbosely spews the compiler output in a format compatible with the VS log window – double-click to jump to file locations, just as you would with the default compiler.


Using Clang you get the benefit of more descriptive and column-specific diagnostics, too. ClangVSx can dump the complete command line invocation, as well as the internal compiler-driver arguments.

Context Menu

Alongside the main menu additions, ClangVSx adds a context-menu to the editor that allows the developer to fire off Clang-specific tasks on the current source file.

It becomes trivial to bring up the LLVM bitcode representation of compiled source, or the output from the C/C++ preprocessor (a feature, I might add, that I wish Visual Studio had built-in itself, like CodeWarrior used to have)


A settings dialog controls which compiler package to target, along with various global settings and diagnotics outputs. You can also override the target-triple, if you fancy trying to compile projects for ARM or something.

It is not all plain sailing, however:

  • Clang is not entirely MS/Win32 friendly – there are huge gaps in the MSVC C++ ABI support (as of writing), along with various core intrinsics not being available yet (__debugbreak, for example)
  • Compiling ATL/MFC apps is currently not trivial, or infact possible at all in most cases – there are a few critical incompatibilities with the afx headers in the Windows Platform SDK

There are a few patches applied to my local version of Clang that improve the success rate when compiling Win32 projects. I have a pre-built version of Clang 3.2 available here. The nature of the patches can be found on the GitHub page. If you just want to play about with the compiler and see what works, I would recommend using this prebuilt version.

The ClangVSx source code and built executables are available on GitHub.
Release notes and version information (ie. what works and what probably doesn’t) can also be found there.


40 Responses to ClangVSx

    Devin says:

    Can you point your readers to the patches for the clang bugs you mention? (9277 and 9213) It seems as though they were fixed somewhere in the trunk, but I can’t tell where or what the fix was.

    ishani says:

    Hi Devin – I have yet to submit patches for these (and a couple of other changes) .. when they are in, and accepted, I’ll update this page (and the GitHub) with details. Been too busy to keep on top of Clang checkins of late, will have to get latest and try out CVSX again to make sure things are still working…

    Ethan says:

    Is the development ceased? Do you have any plan for up coming Clang 3.0?

    ishani says:

    Not ceased – have been very busy with work recently, should have some time to get back onto this in December, see if the MSVC support has improved to in the last few months

    spstanley says:

    Does ClangVSx allow Objective-C development within Visual Studio?

    ishani says:

    In theory, yes; I will look to add this explicitly with the new version of ClangVSx – getting the ObjC runtime-side working might be more of a challenge (but then again, I’m no ObjC expert)

    ishani says:

    spstanley – turns out that you can indeed compile it without much hassle (chuck -ObjC++ into the settings). However it’s mostly useless without a runtime – the GNUstep one may be a possibility but I suspect it would be a pain in the arse to get it working in the Win32 environment

    Kelvi says:

    Is it possible to use newer C++11 features with this? I just tried some code that compiles with Xcode4.3.2 and MSVC 2010. But it doesn’t compile under ClangVSx and adding -std=C++11 gives me different errors, seeming to turn off the msvc compatibility support. (Thank you very much for your work)

    ishani says:

    Yeah, it should work – I have been trying it out successfully with variadic templates which VS2010 doesn’t support. Are you definitely pointing it at a recent Clang 3.x install? Checked the list to ensure its a feature that they support? If so, post me a code snippet and I’ll try to reproduce it locally.

    Kelvi says:

    I’m using the pre-built clang from your link above. It does work with the clang the ships with Xcode 4.3.2. It also works with Microsoft’s compiler (which has supported relaxed struct/union rules for some time). My codebase is currently cross-platform/cross-compiler.

    Here’s a code snippet:

    struct Triple
    Triple() {}
    float a, b, c;

    struct Quadruple
    Triple abc; float d;

    float e[4];

    ishani says:

    Adding the -std=C++11 does seem to be required (I’ll put this in the CVSx UI as a toggle), can you let me know what it breaks on your setup? I can compile a few test Win32 projects here with it set with no errors. I can’t see anything in the compiler driver code that disables the ms-compatibility mode when you switch to C++11 ..

    Kelvi says:

    Here’s the error I’m getting:

    c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\vector(933,3) : error: no member named ‘L__FUNCTION__’ in ‘std::vector<Ship *, std::allocator>’
    c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\yvals.h(326,2) : note: expanded from macro ‘_SCL_SECURE_OUT_OF_RANGE’
    c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\yvals.h(262,46) : note: expanded from macro ‘_SCL_SECURE_OUT_OF_RANGE_NO_ASSERT’
    c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\yvals.h(242,45) : note: expanded from macro ‘_SCL_SECURE_INVALID_PARAMETER’
    note: (skipping 2 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)
    c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\crtdefs.h(536,27) : note: expanded from macro ‘_STR2WSTR’
    #define _STR2WSTR(str) __STR2WSTR(str)
    c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\crtdefs.h(535,27) : note: expanded from macro ‘__STR2WSTR’
    #define __STR2WSTR(str) L##str
    (85,0) : note: expanded from macro ‘L’

    ishani says:

    Ah, it’s unlikely to enjoy trying to work with the Secure STL extensions; you can add -D_ITERATOR_DEBUG_LEVEL=0 to the settings to get it compiling but linking will be a problem, thanks to the incomplete support for the full MSVC C++ ABI in Clang.

    You might have luck getting STLPort or uSTL working …

    Kelvi says:

    Thanks for the help. I’ll take another look at it when I have a bit more time and see whether it’s viable for me.

    Dávid Róbert says:

    This whole thing is awesome!

    Would that be possible sometime in the future to make CLang a selectable toolchain, like how one can select ICC, or how one can select the VC versions: To “install” CLang/LLVM to Project Properties -> General -> Platform Toolset?

    ishani says:

    Originally, the CVX code was a VC macro, hence it’s integration via menus and the like. I could potentially work on a proper new full-bore Platform add-in that would allow for tighter integration (like ICC). Will become more of a potential reality as Clang’s MSVC compatibility improves over time…

    Vasileios Anagnostopoulos says:


    is it possible to use the vanilla clang (+mingw runtime) on the visual studio shell 2010?

    idowu Ogunde says:

    Just want to first say thanks for creating ClangVsx and also putting the prebuilt Clang files up on the web for general usage.
    I however have several problems that I’m hoping you can help me with and its regarding getting it to work on Visual Studio 2012 RC.

    I tried manually editing the ClangVSx.AddIn to:

    Microsoft Visual Studio

    but no luck, I kept getting a caused exception error message whenever I restart VS 2012. Also, I cant find the dll file that you mentioned in your readme file so I’m assuming I’ll need to load the ClangVsx solution and compile but alas that also did not compile.

    I was hoping that maybe you have an already compiled version of the dll that’ll work for VS 2012 and also an *.addin file for VS 2012.

    Please any help would be appreciated.
    I know you’ve done a lot of work on this and you’re probably busy with many other things but a detailed tutorial on getting this to work would be really appreciated and beneficial.

    Thanks a lot for your time and happy coding :D


    ishani says:

    Hi Idowu – thanks for trying this out!

    Check the front-page of the blog, I also had problems getting it working but may have a fix for you. There is also a 2012-compiled version + .AddIn file in there if you want it (I don’t think it’s required, the 2010 version should just work)

    ishani says:

    Idowu – I’ve done further testing and fixed up a few problems with the 2012 version. A working update is now on GitHub and explained here :

    Duane says:

    For VS2012 I had to modify CVXBuildSystem.cs to correctly reference the VS110COMNTOOLS env variable. The addin then was able to invoke the compiler.

    ishani says:

    ah. good catch. I have both VS2010 and 2012 installed here so didn’t experience that failing. I will get that fixed and drop a new built version.

    Wayne says:

    Hi there. Thanks for making this awesome plugin!

    I am having a problem compiling a simple C++ program:

    using namespace std;

    int main (int argc, char *argv[])
    cout << "Hello\n";
    return 0;

    I get a whole stream of error messages starting with:
    C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\type_traits(1072,32) : error: '_Ty' does not refer to a value

    I am using your clang3.2_sept2012 binaries with Visual Studio 2012, and I am passing -std=c++0x to the compiler.

    Am I doing something wrong here, or is full C++ not supported yet? Thanks!!!

    Wayne says:

    In my previous posting, the #include did not paste correctly … I actually have #include as you would expect for std::cout. Thanks.

    ishani says:

    Hey Wayne – I’m afraid I’m away at the moment so can’t do testing on my desktop; C++ is certainly supported, Clang 3.2 even has pretty good C++11 support. I’m afraid I’m not sure exactly why youre having problems .. Should point out I haven’t got round to testing with the RTM of 2012, will be doing that soon when I update and build a new drop of Clang too. I’ll let you know if I drag up any problems.

    Nick says:

    I am running Windows 8 and Visual Studio Ultimate 2012.

    I downloaded from your Git repo.

    I created a folder named ‘Addins’ in my Visual Studio 2012 directory, because it isn’t there by default.

    I extracted ClangVSx.AddIn and ClangVSx.dll from the VS_2012 directory in the .zip into the Addins directory I just created.

    Then I start VS 2012 and I get the following error:

    ## quote ##
    The Add-in ‘ClangVSx’ failed to load or caused an exception.
    Would you like to remove this Add-in?
    If you choose yes, the file it was loaded from,
    ‘C:\Users\nick\Documents\Visual Studio 2012\Addins\ClangVSx.Addin’,
    will be renamed.

    Error Message:
    Error number: 80131515
    ## end quote ##

    This is an extremely helpful error message!

    Thankfully, google found the answer for me and I want to share it in case it causes a problem for anyone else. The problem is related to a restriction Windows 7/8 put on files downloaded from the internet. You have to remove that restriction before VS can load the Addin.

    See here for the solution description:


    Wayne says:

    Hi there,

    I tried the latest clang3.2_oct2012 and ClangVSx-0.4.0 that you just released, and I’m still having the same problem with simple usage of iostream and cout as mentioned above. Should all the VS2012 problems be resolved with this new release?


    Anon says:

    I am having the same problem as Wayne when trying to compile C++. But there are no errors during C compilation. Please can you look into the matter.


    MD says:


    Thanks for publishing the binaries! However, I have the same problem as Wayne and Anon are having — I’m unable to compile even the simple, canonical C++ hello world — an attempt to include the standard iostream (which is the first line of the source code) header fails.

    I’m using ClangVSx-0.4.5 with clang3.3_xmas2012 on Microsoft (R) C/C++ Optimizing Compiler Version 17.00.50727.1 (i.e., VS 2012 Update 1).

    Here are the errors I’m getting:

    (I’ve removed the compile errors to avoid bloating the comments – ishani)

    ishani says:

    Clang has problems with Microsoft’s C++ standard library. Given the MS compiler’s occasional deviation from the strict standards when it comes to templates, I am not awfully surprised – plus, Clang still identifies itself as an earlier version of the MS compiler so there could be problems there too.

    Generally, I would recommend trying STLport or similar. While ClangVSx allows you to run Clang from inside VS, there is still a long way to go for it to cleanly consume the Microsoft platform SDK / stdlib / etc.

    Plus, generally, I use it to test compilation rather than complete project building and linking, as there are also gaps in the MS C++ ABI support.

    Jesse says:

    Where can I access the prebuilt .DLL file? Do I have to compile it myself from the source provided on GitHub?

    Sorry for the dense question, but it’s not clear to me where to locate it.

    ishani says:

    Hi Jesse – the libclang.dll is just in the distro on the Clang-Win32 page.

    Denis says:

    LLVM LTO Code Generation …
    LTO-LLC failed.
    -stats -O3 -filetype=obj -o=”Release\/__lto__.obj” “Release\/__lto__.bc”
    llc.exe: Unknown command line argument ‘-stats’. Try: ‘G:\libs\clang3.3_march2013\llc.exe -help’
    llc.exe: Did you mean ‘-load’?

    latest VSx and clang.

    Graeme says:


    Thanks for this, very useful. I am having a couple of issues –

    1) Regarding files in the project and relative paths: I have a file that is force included (Properties->C++->Advanced->Force Included File) in the format “../code/blah/blah_prefix.h” (i.e. relative to the project folder) but it is not found, because the “../” is ignored. There is a similar problem with my custom build step that is copying files – it tries to run this:
    cmd.exe /C copy “%(FullPath)” “..\..\builds\vs2010\debug\application\” but fails to resolve it (cannot find the file).

    It would be great if you can look into it (though obviously I can work around for now).

    2) Some of my projects are generating extra include directives:
    -isystem “c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include” -isystem “c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\atlmfc\include” -isystem “C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include” followed by these errors:

    clang.exe: error: no such file or directory: ‘Files’
    clang.exe: error: no such file or directory: ‘(x86)\Microsoft’
    clang.exe: error: no such file or directory: ‘Visual’
    clang.exe: error: no such file or directory: ‘Studio’
    clang.exe: error: no such file or directory: ’10.0\VC\include -isystem c:\Program’
    clang.exe: error: no such file or directory: ‘Files’

    This is caused by a trailing ‘\’ character in a path in the project’s Additional Include Directories. Removing that will remove these extra -isystem includes, and fix the error.

    3) Also, it seems that “Active Project” means “Startup Project”, so a button to build the currently selected project would be useful, too.


    Matt says:

    Thanks for the good work on this. I too would love to see clang integrated as a proper platform toolset though.

    A minor bug I have found is that ‘rebuild active project’ fails when the project is in a solution folder. I worked around this using code from and this:

    Project p = null;
    foreach (Project project in SolutionProjects.Projects(_applicationObject.Solution.Projects))
    if (project.UniqueName == startUpProj.ToString())
    p = project;

    Thanks again!

    DevO says:

    @Graeme: The fix for problem 2 is available here

    Krishty says:

    Where on GitHub can I find the .dll? I see ClangVSX.AddIn there, but no VS_2010 nor VS_2012 directory and no .dlls either :(

    William Dang says:

    @Krishty You can find the prebuilt binaries at

    ShiftZ says:

    I wonder if it possible to use libc++ or gnu stdlibc++ as standard library with clang. The STLPort is pretty dead and it does not support c++11 features.

    Luke Jones says:

    @Kelvi: That’s actually a problem with cl’s special treatment of L__FUNCTION__

Leave a Reply

Your email address will not be published. Required fields are marked *