如何定义'_LIBCPP_VERSION'

How to define '_LIBCPP_VERSION'?

本文关键字:LIBCPP VERSION 何定义 定义      更新时间:2023-10-16

我发现一些库包括以下代码:

#if defined(_LIBCPP_VERSION) || (_MSC_VER >= 1700)
#define MSGPACK_HAS_STD_UNOURDERED_MAP
#include <unordered_map>
#define MSGPACK_STD_TR1 std
#else   // defined(_LIBCPP_VERSION) || (_MSC_VER >= 1700)
#if __GNUC__ >= 4
#define MSGPACK_HAS_STD_TR1_UNOURDERED_MAP
#include <tr1/unordered_map>
#define MSGPACK_STD_TR1 std::tr1
#endif // __GNUC__ >= 4
#endif  // defined(_LIBCPP_VERSION) || (_MSC_VER >= 1700)

我想知道如何/在哪里定义_LIBCPP_VERSION_MSC_VER,它是否在使用默认的g++中自动检测?

如果我想使用g++-4.7.2怎么办?

_MSC_VER是一个内置的Visual Studio定义。根据本文档,它将被设置为Visual Studio版本。

根据类似的文档,当您包含"一个标准头文件"时,会自动定义_LIBCPP_VERSION。这看起来像是在使用libc++时定义的。

我还在你的代码中看到一个__GNUC__检查。它将测试GCC或兼容GCC的编译器,如Clang。

让我们逐行分解代码:

#if defined(_LIBCPP_VERSION) || (_MSC_VER >= 1700) //Are we using libc++, or is MSVC installed and above a certain version?
//the next three lines set up defines and includes that libc++/MSVC can use
#define MSGPACK_HAS_STD_UNOURDERED_MAP
#include <unordered_map>
#define MSGPACK_STD_TR1 std
#else   // defined(_LIBCPP_VERSION) || (_MSC_VER >= 1700) //MSVC isn't installed and we're not using libc++, so we'll need to check other compilers
#if __GNUC__ >= 4 //Are we running under GCC or a GCC-compliant compiler?
//the next three lines set up similar defines and includes to the libc++/MSVC ones from above, but these are GCC-based
#define MSGPACK_HAS_STD_TR1_UNOURDERED_MAP
#include <tr1/unordered_map>
#define MSGPACK_STD_TR1 std::tr1
#endif // __GNUC__ >= 4 //this ends the GCC test #if block
#endif  // defined(_LIBCPP_VERSION) || (_MSC_VER >= 1700) //this ends the libc++/MSVC test #if block