Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions src/tools/libcxx-version/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,25 @@
// It's nothing more than specifying the name of the standard library implementation (either libstdc++ or libc++)
// and its major version.

#include <iostream>
#include <cstdio>

int main() {
#ifdef _GLIBCXX_RELEASE
std::cout << "libstdc++ version: " << _GLIBCXX_RELEASE << std::endl;
#define name "libstdc++"
#define version _GLIBCXX_RELEASE
#elif defined(_LIBCPP_VERSION)
// _LIBCPP_VERSION follows "XXYYZZ" format (e.g., 170001 for 17.0.1).
// ref: https://github.com/llvm/llvm-project/blob/f64732195c1030ee2627ff4e4142038e01df1d26/libcxx/include/__config#L51-L54
//
// Since we use the major version from _GLIBCXX_RELEASE, we need to extract only the first 2 characters of _LIBCPP_VERSION
// to provide the major version for consistency.
std::cout << "libc++ version: " << std::to_string(_LIBCPP_VERSION).substr(0, 2) << std::endl;
#define name "libc++"
#define version _LIBCPP_VERSION / 10000
#else
std::cerr << "Coudln't recognize the standard library version." << std::endl;
return 1;
#error "Couldn't recognize the standard library version."
#endif

printf("%s version: %d\n", name, version);

return 0;
}