File tree 1 file changed +28
-0
lines changed
1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change
1
+ // Detecting the standard library version manually using a bunch of shell commands is very
2
+ // complicated and fragile across different platforms. This program provides the major version
3
+ // of the standard library on any target platform without requiring any messy work.
4
+ //
5
+ // It's nothing more than specifying the name of the standard library implementation (either libstdc++ or libc++)
6
+ // and its major version.
7
+ //
8
+ // ignore-tidy-linelength
9
+
10
+ #include < iostream>
11
+
12
+ int main () {
13
+ #ifdef _GLIBCXX_RELEASE
14
+ std::cout << " libstdc++ version: " << _GLIBCXX_RELEASE << std::endl;
15
+ #elif defined(_LIBCPP_VERSION)
16
+ // _LIBCPP_VERSION follows "XXYYZZ" format (e.g., 170001 for 17.0.1).
17
+ // ref: https://github.com/llvm/llvm-project/blob/f64732195c1030ee2627ff4e4142038e01df1d26/libcxx/include/__config#L51-L54
18
+ //
19
+ // Since we use the major version from _GLIBCXX_RELEASE, we need to extract only the first 2 characters of _LIBCPP_VERSION
20
+ // to provide the major version for consistency.
21
+ std::cout << " libc++ version: " << std::to_string (_LIBCPP_VERSION).substr (0 , 2 ) << std::endl;
22
+ #else
23
+ std::cerr << " Coudln't recognize the standard library version." << std::endl;
24
+ return 1 ;
25
+ #endif
26
+
27
+ return 0 ;
28
+ }
You can’t perform that action at this time.
0 commit comments