xcode 在编译时检测编译器版本

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3592805/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 19:40:57  来源:igfitidea点击:

Detecting compiler versions during compile time

visual-studioxcodecompiler-construction

提问by Cthutu

This is both a question and a reference and I am hoping that people can build upon this so that it can be reused by people with similar questions.

这既是一个问题也是一个参考,我希望人们可以以此为基础,以便有类似问题的人可以重复使用。

How can we reliably detect a particular version of a C/C++/ObjC compiler? Now I know the answer for Visual Studio and partially know the answer for Xcode.

我们如何可靠地检测特定版本的 C/C++/ObjC 编译器?现在我知道了 Visual Studio 的答案并且部分知道了 Xcode 的答案。

Now for the Visual Studio compiler we have _MSC_VER which is defined with these values:

现在对于 Visual Studio 编译器,我们有 _MSC_VER 定义了这些值:

Version 1.0    800
Version 2.0    900
Version 2.x    900
Version 4.0    1000
Version 5.0    1100
Version 6.0    1200
Version 7.0    1300
Version 7.1    1310
Version 8.0    1400  (Visual Studio 2005)
Version 9.0    1500  (Visual Studio 2008)
Version 10.0   1600  (Visual Studio 2010)
Version 11.0   1700  (Visual Studio 2012)

Now for the Xcode compiler we have this define:

现在对于 Xcode 编译器,我们有这样的定义:

__APPLE_CC__

But the only values I've managed to find via google (Mac docs don't seem to have these values) are:

但我设法通过谷歌找到的唯一值(Mac 文档似乎没有这些值)是:

Xcode 3.0              5465
Xcode 3.1              5470
Xcode 3.1 (GCC 4.2)    5553
Xcode 3.2.3            5664  (Got this value from my own compiler)

Can anyone complete this list or provide links to a full list? And maybe we can provide information for other compilers too.

任何人都可以完成此列表或提供完整列表的链接吗?也许我们也可以为其他编译器提供信息。

采纳答案by Stephen Gennard

As someone who has ported more than his fair share of 'C' around, I can see were you are coming from, so here is some to get us started:

作为一个移植了超过他公平份额的“C”的人,我可以看出你来自哪里,所以这里有一些让我们开始:

For IBM CL/C++ compiler product:

对于 IBM CL/C++ 编译器产品:

__xlc__  - Format is V.R.M.F eg: "9.0.0.0"
__IBMCPP__ Format is an integer as VRM eg: V9.0 is 900
__IBMC__ - Format is an integer as VRM, 
           which indicates the level of compiler as VRM as:
< 200 is C Set/2
< 300 is C Set++
otherwise is Visual Age C++ V.M.C

           where V=version, M=release, M=modification and F=fix level.

For Borland C:

对于 Borland C:

___BORLANDC__ ??

For GNU C:

对于GNU C

__GNUC__ ??

For Watcon C:

对于 Watcon C:

__WATCOMC__

回答by Jesse Chisholm

There is a table of this information here:

此处有此信息的表格:

https://sourceforge.net/p/predef/wiki/Compilers/

https://sourceforge.net/p/predef/wiki/Compilers/

Sadly, It appears that MacOS defines __clang__, __GNUCC__and __llvm__so this information can get a little confused.

可悲的是,它似乎是MacOS的定义__clang____GNUCC____llvm__因此,这些信息可以得到一点点迷惑。

But usually, only one set of information applies.

但通常,只有一组信息适用。