
本文介绍了如何通过#define指令检测LLVM及其版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这个问题很清楚我想。我试图写一个编译器检测头,以便能够包括在使用哪个编译器的应用程序信息和哪个版本。
这是代码的一部分I 'm using:
/ * GNU C编译器检测* /
#elif已定义__GNUC__
#ifdef __MINGW32__
#define COMPILERMinGW GCC%d。%d。%d
#else
#define COMPILERGCC%d。%d。%d
#endif
#define COMP_VERSION __GNUC__,__GNUC_MINOR__,__GNUC_PATCHLEVEL__
#endif
使用像这样:
printf(Compiled usingCOMPILER\\\
,COMP_VERSION);
有没有办法检测LLVM及其版本? __ llvm __
和
__clang __
宏是分别检查LLVM编译器(llvm-gcc或clang)或clang的正式方式。
__ has_feature
和 __ has_builtin
是使用clang时检查可选编译器功能的推荐方法,它们记录在。
请注意,您可以找到一个列表的gcc,llvm-gcc和clang的内置编译器宏:
echo | clang -dM -E -
这将预处理一个空字符串,并输出编译器定义的所有宏。
The question is quite clear I think. I'm trying to write a compiler detection header to be able to include in the application information on which compiler was used and which version.
This is part of the code I'm using:
/* GNU C Compiler Detection */
#elif defined __GNUC__
#ifdef __MINGW32__
#define COMPILER "MinGW GCC %d.%d.%d"
#else
#define COMPILER "GCC %d.%d.%d"
#endif
#define COMP_VERSION __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__
#endif
Which could be used like this:
printf(" Compiled using " COMPILER "\n", COMP_VERSION);
Is there any way to detect LLVM and its version? And CLANG?
解决方案
The __llvm__
and __clang__
macros are the official way to check for an LLVM compiler (llvm-gcc or clang) or clang, respectively.
__has_feature
and __has_builtin
are the recommended way of checking for optional compiler features when using clang, they are documented here.
Note that you can find a list of the builtin compiler macros for gcc, llvm-gcc, and clang using:
echo | clang -dM -E -
This preprocesses an empty string and spits out all macros defined by the compiler.
这篇关于如何通过#define指令检测LLVM及其版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!