mardi 21 juin 2016

How to get the boost_major_version number automatically?


Previously on Ubuntu, we can do the following to get the boost_major_version:

echo "$boost_cv_lib_version" | sed 's/_//;s/_.*//'

For whatever reason, Ubuntu changes when upgrading from version 14.04 to 16.04 and now I have to do the following to find my Boost version:

dpkg -s libboost-dev | grep 'Version'

And the current version of boost installed using sudo apt install libboost-all-dev is:

Version: 1.58.0.1ubuntu1

Given this, I would require the major version, i.e. 158.

Other than manually looking at it knowing it's 158? I've tried some regexes but I couldn't get it correct to strip the string: Version: 1.58.0.1ubuntu1 to 158.

I've tried:

alvas@ubi:~/repp$ dpkg -s libboost-dev | grep 'Version' 
Version: 1.58.0.1ubuntu1
alvas@ubi:~/repp$ dpkg -s libboost-dev | grep 'Version' | cut -d' ' -f2 | grep -oP '([0-9].*.[0-9].*).' 
1.58.0.

But I also understand that the -P option might not be available on linux platforms.

I could do this by piping into Python to do the dirty string works but that's a little too much... I'm sure there's a better way:

alvas@ubi:~/repp$ dpkg -s libboost-dev | grep 'Version' | python -c "import re,sys; print re.findall(r'([0-9].*.[0-9].*).[0-9].*.', sys.stdin.readline())[0].replace('.', '')"
158

So the question is:

  • How do I get the boost_major_version on Ubuntu 16.04?

  • If dpkg -s libboost-dev | grep 'Version' is the only way to do it, how do I strip Version: 1.58.0.1ubuntu1 -> 158?


Aucun commentaire:

Enregistrer un commentaire