如何在编译时测试libstdc++的版本,而不是GCC
How do I test the version of libstdc++, not GCC, at compile time?
我正在尝试测试libstdc++
的版本,因为std::regex
在4.9.0版本之前与GCC一起分发的libstdc++
版本中实现了,但很大程度上是破碎的。
注意:
-
我需要测试
libstdc++
的版本,而不是GCC,因为Clang也支持使用libstdc++
作为标准库。这就排除了测试__GNUC_PATCHLEVEL__
、__GNUC__
和__GNUC_MINOR__
宏的可能性。 -
__GLIBCXX__
宏是一个日期,而不是版本号,并且不单调递增。例如,GCC 4.8.4附带了#define __GLIBCXX__ 20150426
,它比GCC 4.9.0的发布日期更新。
是否有任何可移植的方法来测试libstdc++
的版本,不依赖于使用GCC我的编译器?
我认为这个问题很小,可以用蛮力解决。
在名为machine.hpp
或类似的头文件中,我会测试c++标准的版本至少是我需要的(__cplusplus
宏)。然后,我将添加各种宏检查,以拒绝任何我知道有缺陷的库。
换句话说,我将采用黑名单方法而不是白名单方法。例如:
#pragma once
#ifndef MACHINE_HPP_HEADER_GUARDS
#define MACHINE_HPP_HEADER_GUARDS
#if __cplusplus < 201103L
// Library is incompatible if it does not implement at least the C++11
// standard.
#error "I need a library that supports at least C++11."
#else
// Load an arbitrary header to ensure that the pre-processor macro is
// defined. Otherwise you will need to load this header AFTER you
// #include the header you care about.
#include <iosfwd>
#endif
#if __GLIBCXX__ == 20150422
#error "This version of GLIBCXX (20150422) has flaws in it"
#endif
// ...repeat for other versions of GLIBCXX that you know to be flawed
#endif // MACHINE_HPP_HEADER_GUARDS
相关文章:
- 在clang++预处理器中确定gcc工具链版本
- 如何指示 cmake 的 gcc 版本?
- 不同版本的编译器(例如GCC)是否会产生不同的性能?
- g++ libstdc++.so.6:从 4.8.5 升级到 GCC 版本 7.3.0 后找不到版本 'CXXABI_1.3.9'
- 为什么库API+编译器ABI足以确保具有不同版本gcc的对象之间的兼容性
- GCC:--静态链接到pthread的整个存档配方在最近的GCC版本中停止工作
- glibc 版本比 gcc 版本和 -wl,-rpath 不工作
- 三元运算符 '?:' 在 4.9.0 之前的 GCC 版本中推断出不正确的类型?
- 使用不同版本的 gcc 和 g++ 进行编译时出现问题
- 在CentOS 7上安装GCC 7.4.0不会更新我的LIBSTDC 版本
- 与NVIDIA链接的错误GCC版本
- 是否有编译器标志可以使较新的 gcc 版本像旧版本一样构建
- GCC编译器,为较低版本的GCC编译应用程序
- 所有版本的 GCC 都与默认成员初始值设定项作斗争,该初始值设定项捕获了这一点,并结合了继承的构造函数
- 不同的内在行为取决于 GCC 版本
- 所有版本的 GCC 都在与定义中具有默认类型的模板作斗争
- 如何在使用旧版本gcc的系统上动态链接到libc.so.6、libstdc++.so.6的本地副本
- 暂时禁用特定版本GCC上的警告
- 在使用旧版本gcc / glibc / libstdc++的计算机上运行用gcc 4.7编译的c++ 11可执行文件的问
- 对于使用旧版本gcc的系统,使用gcc进行构建