How to determine the Boost version on a system?
Asked Answered
E

15

169

Is there a quick way to determine the version of the Boost C++ libraries on a system?

Esra answered 14/9, 2010 at 12:8 Comment(0)
F
106

Boost Informational Macros. You need: BOOST_VERSION

Foreclosure answered 14/9, 2010 at 12:11 Comment(4)
If you want to figure it out manually (rather than in-code), the go to the include directory, and open up version.hpp. BOOST_VERSION takes a bit of deciphering, but BOOST_LIB_VERSION is pretty clear. The value of mine is currently "1_42"Daughterinlaw
In linux, using "ldd yourprogramname" will often show you which version of boost was linked to your program (which has the possibility of indicating a difference from the header, though it's unlikely to be different).Mcmurray
Also in linux, dpkg -S /usr/include/boost/version.hppPenuche
You can quickly look up the current value via e.g. echo -e '#include <boost/version.hpp>\nBOOST_VERSION' | gcc -x c++ -E - - for example on Fedora 26: 106300 (i.e. 1.63)Stumer
H
92

Include #include <boost/version.hpp>

std::cout << "Using Boost "     
          << BOOST_VERSION / 100000     << "."  // major version
          << BOOST_VERSION / 100 % 1000 << "."  // minor version
          << BOOST_VERSION % 100                // patch level
          << std::endl;

Possible output: Using Boost 1.75.0

Tested with Boost 1.51.0 to 1.63, 1.71.0 and 1.76.0 to 1.83.0

Hegemony answered 26/10, 2012 at 9:50 Comment(4)
what a dedication sir @HegemonyEvaluate
To break @Hegemony 's streak: Works also with 1.60.0 and 1.61.0.Condensate
@Hegemony They should hire you for any kind of release changes.Phallicism
Why don't you just update your answer with something like: 'Works with all Boost versions (tested version 1.51 to 1.63 ).' - instead of overflowing the comment section ...Stumer
C
76

If you only need to know for your own information, just look in /usr/include/boost/version.hpp (Ubuntu 13.10) and read the information directly

Calmative answered 10/2, 2014 at 23:27 Comment(0)
M
47
#include <boost/version.hpp>
#include <iostream>
#include <iomanip>

int main()
{
    std::cout << "Boost version: " 
          << BOOST_VERSION / 100000
          << "."
          << BOOST_VERSION / 100 % 1000
          << "."
          << BOOST_VERSION % 100 
          << std::endl;
    return 0;
}

Update: the answer has been fixed.

Motherhood answered 14/9, 2010 at 12:20 Comment(6)
Why not just: std::cout << "Boost version: " << BOOST_LIB_VERSION;?Daughterinlaw
Running this code outputted "Boost version: 0.199.60" whereas T.E.D.'s version outputted "Boost version: 1_48"Mcmurray
This doesn't work. Why would any one upvote this? Has anybody actually run this code and gotten useful output? I guess people see "hex" and figure it must be correct.Dwarfish
The answer by Vertexwahn is how the docs say to use BOOST_VERSIONCoimbatore
This is not correct. Boost version is stored decimally, not hexagonally.Drops
Except now it's just the same thing as the other answer...Poetize
W
25

Depending on how you have installed boost and what OS you are running you could also try the following:

dpkg -s libboost-dev | grep 'Version'
Wells answered 27/2, 2017 at 14:31 Comment(1)
Is libboost-dev the same as "boost"? Because I have a lot in /usr/include/boost but your command gives is not installed.Heliometer
S
9

Boost installed on OS X using homebrew has desired version.hpp file in /usr/local/Cellar/boost/<version>/include/boost/version.hpp (note, that the version is already mentioned in path).

I guess the fastest way to determine version on any UNIX-like system will be to search for boost in /usr:

find /usr -name "boost"

Schlessel answered 14/10, 2016 at 13:39 Comment(1)
My include was empty so I used the version at the end of the lib files: find / -name *boost*.so* 2>/dev/nullKnavish
M
6

As to me, you can first(find version.hpp the version variable is in it, if you know where it is(in ubuntu it usually in /usr/include/boost/version.hpp by default install)):

 locate `boost/version.hpp`

Second show it's version by:

 grep BOOST_LIB_VERSION /usr/include/boost/version.hpp

or

  grep BOOST_VERSION /usr/include/boost/version.hpp.

As to me, I have two version boost installed in my system. Output as below:

xy@xy:~$ locate boost/version.hpp |grep boost

/home/xy/boost_install/boost_1_61_0/boost/version.hpp
/home/xy/boost_install/lib/include/boost/version.hpp
/usr/include/boost/version.hpp

xy@xy:~$ grep BOOST_VERSION /usr/include/boost/version.hpp
#ifndef BOOST_VERSION_HPP
#define BOOST_VERSION_HPP
//  BOOST_VERSION % 100 is the patch level
//  BOOST_VERSION / 100 % 1000 is the minor version
//  BOOST_VERSION / 100000 is the major version
#define BOOST_VERSION 105800
//  BOOST_LIB_VERSION must be defined to be the same as BOOST_VERSION

# or this way more readable
xy@xy:~$ grep BOOST_LIB_VERSION /usr/include/boost/version.hpp
//  BOOST_LIB_VERSION must be defined to be the same as BOOST_VERSION
#define BOOST_LIB_VERSION "1_58"

Show local installed version:

xy@xy:~$ grep BOOST_LIB_VERSION /home/xy/boost_install/lib/include/boost/version.hpp
//  BOOST_LIB_VERSION must be defined to be the same as BOOST_VERSION
#define BOOST_LIB_VERSION "1_61"
Munda answered 4/8, 2018 at 1:54 Comment(0)
C
6

I stugeled to find out the boost version number in bash.

Ended up doing following, which stores the version code in a variable, supressing the errors. This uses the example from maxschlepzig in the comments of the accepted answer. (Can not comment, don't have 50 Rep)

I know this has been answered long time ago. But I couldn't find how to do it in bash anywhere. So I thought this might help someone with the same problem. Also this should work no matter where boost is installed, as long as the comiler can find it. And it will give you the version number that is acutally used by the comiler, when you have multiple versions installed.

{
VERS=$(echo -e '#include <boost/version.hpp>\nBOOST_VERSION' | gcc -s -x c++ -E - | grep "^[^#;]")
} &> /dev/null
Carven answered 18/2, 2019 at 16:58 Comment(1)
Nice approach and like that it uses <boost/version.hpp> rather than explicit path.Saintly
R
6

@Vertexwahns answer, but written in bash. For the people who are lazy:

boost_version=$(cat /usr/include/boost/version.hpp | grep define | grep "BOOST_VERSION " | cut -d' ' -f3)
echo "installed boost version: $(echo "$boost_version / 100000" | bc).$(echo "$boost_version / 100 % 1000" | bc).$(echo "$boost_version % 100 " | bc)"

Gives me installed boost version: 1.71.0

Reek answered 22/10, 2020 at 8:10 Comment(0)
C
4

Another way to get current boost version (Linux Ubuntu):

~$ dpkg -s libboost-dev | grep Version
Version: 1.58.0.1ubuntu1

Ref: https://www.osetc.com/en/how-to-install-boost-on-ubuntu-16-04-18-04-linux.html

Coattail answered 15/9, 2019 at 1:0 Comment(0)
A
3

cat /usr/local/include/boost/version.hpp | grep BOOST_LIB_VERSION

Admass answered 21/1, 2021 at 4:40 Comment(1)
please elaborateAmazon
C
1

If one installed boost on macOS via Homebrew, one is likely to see the installed boost version(s) with:

ls /usr/local/Cellar/boost*
Cammycamomile answered 26/4, 2020 at 8:48 Comment(0)
L
0

Might be already answered, but you can try this simple program to determine if and what installation of boost you have :

#include<boost/version.hpp>
#include<iostream>
using namespace std;
int main()
{
cout<<BOOST_VERSION<<endl;
return 0;
}
Lynea answered 20/3, 2018 at 16:6 Comment(1)
It has already been answered, almost a decade ago, and you can plainly see that by simply reading this page.Shae
U
0

All the answers above are pretty good. However, I wondered if I can type in my terminal simple command boost --version just like I usually do for any other tool. So I implemented it in C++:

#include <iostream>
#include <string>
#include <boost/version.hpp>

int main(int argc, char *argv[])
{
    if (argc >= 2) {
        if (std::string arg(argv[1]); arg == "--version" || arg == "-v") {
            auto major_version = BOOST_VERSION / 100000;
            auto minor_version = BOOST_VERSION / 100 % 1000;
            auto patch_version = BOOST_VERSION % 100;

            std::cout   
                << "Boost library version: "
                << major_version << '.'
                << minor_version << '.'
                << patch_version << '\n';
        }
        else if (arg == "--help" || arg == "-h") {
            std::cout
                << "This is small helper utility to figure out installed Boost version.\n"
                << "Use --version parameter to print installed Boost library version.\n\n"
                << "Boost is a set of libraries for the C++ programming language that provides\n"
                << "support for tasks and structures such as linear algebra, pseudorandom number\n"
                << "generation, multithreading, image processing, regular expressions, and unit testing.\n"
                << "If you want to know more about Boost please visit https://www.boost.org\n";
        }
        else {
            std::cout
                << "Unknown parameter " << arg 
                << ". Use --version or --help as a parameter instead.\n";
        }
    }
}

Then I built it using following command:
g++ -Wextra -Wall -pedantic -std=c++20 main.cpp -o boost
to get executable named just "boost". When it has been done I copied this executable to my /usr/bin using following command:
sudo cp -r ./boost /usr/bin
Since then I'm able to type in my terminal boost --version to figure out installed Boost version.

Ugrian answered 23/4, 2023 at 21:31 Comment(0)
W
0

Can it really be that no one has suggested that, at least from the advent of Boost Predef with Boost 1.55.0, we can:

#include <boost/predef.h>
#include <boost/version.hpp>
...
#if BOOST_VERSION < BOOST_VERSION_NUMBER(1, 67, 0)

... if we wanted, for example, to know whether a work around was needed for this ~2038 problem in Boost DateTime? Perhaps it's a minority-interest reading of the question, but it's the one that brought me here.

No, and it's as well they shouldn't, because it doesn't work. The BOOST_VERSION_NUMBER macro from Boost Predef is incompatible with Boost's own version number! I don't see that documented as recently as Boost 1.84.0. I like the two stage idea, though, so I'll use:

#include <boost/version.hpp>
...
#define BOOSTS_OWN_VERSION_NUMBER(major, minor, patch) ((major) * 100 * 1000 + (minor) * 100 + (patch))
#if BOOST_VERSION < BOOSTS_OWN_VERSION_NUMBER(1, 67, 0)
Wen answered 13/3 at 21:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.