如何检测Clang中的libstdc ++版本? [英] How to detect the libstdc++ version in Clang?

查看:883
本文介绍了如何检测Clang中的libstdc ++版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Clang中编写一个便携式C ++库。 可移植意味着我(在C预处理器中)检测编译环境中可用的C ++功能,并使用这些功能或提供我的解决方法。这与Boost库正在做的类似。



但是,某些功能的存在不取决于语言,而取决于标准库实现。我特别感兴趣的是:




  • 输入traits(其中有可用的和用什么拼写)

  • 如果 initializer_list constexpr



我发现这个问题,因为Clang默认不使用自己的标准库实现:它使用libstdc ++。虽然Clang已预定义预处理程序宏 __ GNUC __ __ GNUC_MINOR __ __ GNUC_PATCHLEVEL __ ,它们分别硬编码为值4,2,1,他们告诉我一些关于可用的libstdc ++功能。



如何检查Clang预处理程序什么版本的libstdc ++它使用自己的标准库实现,它被称为 libcxx.llvm.org/rel =nofollow> libc ++ 。你可以通过添加 -stdlib = libc ++ 到你的编译命令来使用它。



检查方式Clang / libstdc ++ C ++支持:


  1. Clang有 __ has_feature 宏(和朋友),可用于检测语言特性和语言扩展。 li>
  2. Libstdc ++有自己的版本宏,请参见文档。你需要包含一个libstdc ++头文件来获得这些定义。

  3. GCC有你已经发现的版本宏,但是需要手动比较文档。 li>

而且,这花了我2分钟的时间。


I would like to write a "portable" C++ library in Clang. "Portable" means that I detect (in C preprocessor) what C++ features are available in the compilation environment and use these features or provide my workarounds. This is similar to what Boost libraries are doing.

However, the presence of some features depends not on the language, but on the Standard Library implementation. In particular I am interested in:

  • type traits (which of them are available and with what spelling)
  • if initializer_list being constexpr.

I find this problematic because Clang by default does not use its own Standard Library implementation: it uses libstdc++. While Clang has predefined preprocessor macros __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__, they are hardcoded to values 4, 2, 1 respectively, and they tell me little about the available libstdc++ features.

How can I check in Clang preprocessor what version of libstdc++ it is using?

解决方案

Clang does come with its own standard library implementation, it's called libc++. You can use it by adding -stdlib=libc++ to your compile command.

That being said, there are various ways to check Clang/libstdc++ C++ support:

  1. Clang has the __has_feature macro (and friends) that can be used to detect language features and language extenstions.
  2. Libstdc++ has its own version macros, see the documentation. You'll need to include a libstdc++ header to get these defined though.
  3. GCC has its version macros which you already discovered, but those would need to be manually compared to the documentation.

And also, this took me 2 minutes of googling.

这篇关于如何检测Clang中的libstdc ++版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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