如何在编译时测试GCC当前版本?
我想根据 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。
我很确定在预处理时定义了一个变量,但我只是找不到它了。
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
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
应根据您的需要定义许多宏:
版本格式为major.minor.patch,例如4.0.2
这些的文档可以找到此处。
There are a number of macros that should be defined for your needs:
The version format is major.minor.patch, e.g. 4.0.2
The documentation for these can be found here.
好的,经过更多搜索,一种可能的方法是使用
features.h
中定义的__GNUC_PREREQ
。Ok, after more searches, it one possible way of doing it is using
__GNUC_PREREQ
defined infeatures.h
.附注:
要查找所有预定义的宏:
g++ -E -dM t.cpp
As a side note:
To find all the predefined macros:
g++ -E -dM t.cpp