[英]How to test the current version of GCC at compile time?
我想根據GCC的版本包含不同的文件。 更准確地說,我想寫:
#if GCC_VERSION >= 4.2
# include <unordered_map>
# define EXT std
#elif GCC_VERSION >= 4
# include <tr1/unordered_map>
# define EXT std
#else
# include <ext/hash_map>
# define unordered_map __gnu_cxx::hash_map
# define EXT __gnu_cxx
#endif
我不關心3.2之前的gcc。
我很確定在預處理時間定義了一個變量,我再也找不到了。
應根據您的需要定義許多宏:
__GNUC__ // major
__GNUC_MINOR__ // minor
__GNUC_PATCHLEVEL__ // patch
版本格式為major.minor.patch,例如4.0.2
這些文檔可以在這里找到。
好了,經過搜索,它一個這樣做的可能的方式是使用__GNUC_PREREQ
定義features.h
。
#ifdef __GNUC__
# include <features.h>
# if __GNUC_PREREQ(4,0)
// If gcc_version >= 4.0
# elif __GNUC_PREREQ(3,2)
// If gcc_version >= 3.2
# else
// Else
# endif
#else
// If not gcc
#endif
作為旁注:
要查找所有預定義的宏:
g++ -E -dM t.cpp
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.