Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
882 views
in Technique[技术] by (71.8m points)

c++ - How to get platform IDs from boost?

How can we know which operating system the code is running?

e.g. How to know the operating system like Unix-Linux, Solaris, HP Unix, Windows, Mac etc?

How can we determine operating system in C++ code with boost? I want to test with Boost v1.41 onwards.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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     << "
";
}

Which prints

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

Or on my own machine

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...