How to tell Clang to stop pretending to be other compilers?

前端 未结 3 1260
梦毁少年i
梦毁少年i 2020-12-18 20:51

I\'ve run into this issue in the past: LLVM defines __GNUC__, but it can\'t consume a program GCC can. I\'m experiencing it again on Windows: LLVM defines _MSC_VER, but it c

3条回答
  •  情歌与酒
    2020-12-18 21:46

    How do we tell Clang to stop pretending to be other compilers?

    I don't know how to do that, nor whether it's even do-able. Why do you want to do this? I have the feeling you want to do this to work around a problem, but perhaps there's a better solution.

    [On Windows,] LLVM defines _MSC_VER,

    Because you're likely using a standard library that's going to check that in order to produce compatible code.

    Clang's goal on Windows is not just to produce standalone code that runs on Windows, but code that can be linked with libraries that were compiled with VC++. From the source code's point of view, it should be indistinguishable whether it's being compiled with clang or VC++.

    If you want to be able to call into an existing DLL, and its header files check _MSC_VER, you need it set whether you're using VC++ or clang.

    but [clang on Windows] can't consume the same program VC++ can.

    Clang's capabilities on Windows have improved quite a bit since this question was written. Several major projects now use clang for their Windows versions.

    If you find a correct program that VC++ accepts and clang doesn't, please file a bug report. In most cases, this is probably an oversight. There are a small number of features and VC++ extensions that are not implemented in clang-on-Windows because they weren't a high enough priority. If they're a priority for you, please let us know.

提交回复
热议问题