如何从 boost 中获取平台 ID?
我们如何知道代码运行的是哪个操作系统?
How can we know which operating system the code is running?
例如如何了解Unix-Linux、Solaris、HP Unix、Windows、Mac等操作系统?
e.g. How to know the operating system like Unix-Linux, Solaris, HP Unix, Windows, Mac etc?
我们如何使用 boost 确定 C++ 代码中的操作系统?我想从 Boost v1.41 开始测试.
How can we determine operating system in C++ code with boost? I want to test with Boost v1.41 onwards.
推荐答案
快速扫描 version.hpp
/config.hpp
后发现:
These are things a quick scan of version.hpp
/config.hpp
revealed:
Live On Coliru强>
#include <boost/version.hpp>
#include <boost/config.hpp>
#include <iostream>
int main() {
std::cout << "BOOST_VERSION " << BOOST_VERSION << "
";
std::cout << "BOOST_LIB_VERSION " << BOOST_LIB_VERSION << "
";
std::cout << "BOOST_PLATFORM " << BOOST_PLATFORM << "
";
std::cout << "BOOST_PLATFORM_CONFIG " << BOOST_PLATFORM_CONFIG << "
";
std::cout << "BOOST_COMPILER " << BOOST_COMPILER << "
";
#ifdef BOOST_LIBSTDCXX_VERSION
std::cout << "BOOST_LIBSTDCXX_VERSION " << BOOST_LIBSTDCXX_VERSION << "
";
#endif
#ifdef BOOST_LIBSTDCXX11
std::cout << "Compiled with c++11 support enabled
";
#endif
std::cout << "BOOST_STDLIB " << BOOST_STDLIB << "
";
std::cout << "BOOST_STDLIB_CONFIG " << BOOST_STDLIB_CONFIG << "
";
}
打印出来的
BOOST_VERSION 106400
BOOST_LIB_VERSION 1_64
BOOST_PLATFORM linux
BOOST_PLATFORM_CONFIG boost/config/platform/linux.hpp
BOOST_COMPILER Clang version 3.8.0 (tags/RELEASE_380/final 263969)
BOOST_STDLIB libc++ version 1101
BOOST_STDLIB_CONFIG boost/config/stdlib/libcpp.hpp
或者在我自己的机器上
BOOST_VERSION 106500
BOOST_LIB_VERSION 1_65
BOOST_PLATFORM linux
BOOST_PLATFORM_CONFIG boost/config/platform/linux.hpp
BOOST_COMPILER GNU C++ version 7.2.0
BOOST_LIBSTDCXX_VERSION 70200
Compiled with c++11 support enabled
BOOST_STDLIB GNU libstdc++ version 20170818
BOOST_STDLIB_CONFIG boost/config/stdlib/libstdcpp3.hpp
相关文章