如何在编译时测试当前版本的GCC? [英] How to test the current version of GCC at compile time?

查看:111
本文介绍了如何在编译时测试当前版本的GCC?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想根据GCC的版本添加其他文件.更准确地说,我想写:

I would like to include a different file depending on the version of GCC. More precisely I want to write:

#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.

I don't care about gcc before 3.2.

我很确定在预处理时为此定义了一个变量,只是找不到了.

I am pretty sure there is a variable defined at preprocessing time for that, I just can't find it again.

推荐答案

好吧,在进行更多搜索之后,一种可行的方法是使用features.h中定义的__GNUC_PREREQ.

Ok, after more searches, it one possible way of doing it is using __GNUC_PREREQ defined in 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

这篇关于如何在编译时测试当前版本的GCC?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆