8

I installed LLVM for Windows, which includes Clang and a few other tools. It integrates with Visual Studio, and even lets me choose a "Platform Toolset" in the project properties. However, when I choose any of the toolsets that came with LLVM, __clang__ isn't defined, and _MSC_VER is defined instead. How do I make __clang__ defined when using LLVM and Clang in Visual Studio?

My Visual Studio version is the 2015 Preview (however I have also tested on 2013 with no success either), and my LLVM version is based off of SVN release 225473. I've tried LLVM-vs2012, LLVM-vs2013, and LLVM-vs2014 as the Platform Toolset without success.

8
  • 2
    If you want to detect LLVM, check __llvm__. Clang is a GCC replacement, which an MSVC toolset isn't. Commented Jan 19, 2015 at 6:01
  • 1
    I am quite sure __clang__ is also defined, at least it was last time I have tested it. Make sure you are checking __clang__ before _MSC_VER. Commented Jan 19, 2015 at 20:09
  • 1
    Neither __clang__ nor __llvm__ are defined when using the Platform Toolset in Visual Studio. I got the toolset from llvm.org/builds Commented Jan 19, 2015 at 21:08
  • Have you ever found a solution to this, other than defining clang your own? I have a similar problem but it seems I can not add a custom definition in my environment. Commented Dec 21, 2018 at 13:59
  • @Silicomancer even I'm facing the same issue as your's can u tell me how u solved it i.e without defining clang Commented Mar 17, 2020 at 12:09

1 Answer 1

3

Under Project Properties -> C/C++ -> Preprocessor -> Preprocessor Definitions, add __clang__. Yes, this is just a workaround.

Sign up to request clarification or add additional context in comments.

1 Comment

I guess I can use this for now, as at this point I'm wondering if it's just an oversight on Microsoft's part.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.