Duplicated header between Clang and MSVC - why?

Hello Clang-Experts,

I’m using Clang-CL in Visual Studio – everything is working fine! Hooray!

But recently I noticed that some header files related to the C-Library are duplicated on my hard drive. For example: stddef.h – so I searched for it and noticed, that Visual Studio has like… 5 of them, but all related to different versions of MSVC. That made sense to me, but then: surprise! I also have that file under “C:\Program Files\LLVM9\lib\clang\9.0.0\include” being obviously related to Clang. I also noticed that there are many files duplicated between Clang and MSVC.

Now I wonder… If I run Clang-CL, should I use the most up to date MSVC header or the Clang one?

Why are these files duplicated anyway?

I feel like, that this is a silly question, but I seriously have no idea.

Kind greetings

Björn

Certain low level headers are very tightly tied to the compiler implementation (containing compiler intrinsics, etc) - so they have to be provided by/paired with the compiler.

Hello Clang-Experts,

I’m using Clang-CL in Visual Studio – everything is working fine! Hooray!

Glad to hear it! :slight_smile:

Now I wonder… If I run Clang-CL, should I use the most up to date MSVC header or the Clang one?

If you use clang-cl, it should automatically use some combination of both sets of headers. You can see in vadefs.h, for example, #include_next is used like so:
#include_next <vadefs.h>

So both clang and MSVC’s vadefs.h header is used.

Why are these files duplicated anyway?

What David said is correct. The headers that clang ships tend to define things that are tightly coupled to the compiler. See the way clang implements the intel intrinsics, for example, by looking at the mmintrin.h header.

Thank you David and Reid!

The background for this question is, that I we have a tool that creates C code – then it runs Clang-Cl as an external tool to create object files. The user however will not have a full C/C++ development environment so we planed on only “shipping” the needed header files. For some tests I used all Visual Studio headers and everything compiled fine – I simply added all paths with -I

So if I have a ‘duplicated’ header, would it be better to use the Clang header? Or should I include both header in the search path?

Kind greetings and thank you again

Björn

I think in the end because of the usage of include_next it will be necessary to have two directories of headers:

  • clang’s headers
  • msvc’s headers
    The search path has to put clang’s first and MSVC’s second. In this context, the organization could be up to you.