C++ 如何确定系统上的 Boost 版本?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3708706/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to determine the Boost version on a system?
提问by Jan Deinhard
Is there a quick way to determine the version of the Boost C++ libraries on a system?
有没有一种快速的方法来确定系统上 Boost C++ 库的版本?
采纳答案by AraK
Boost Informational Macros. You need: BOOST_VERSION
提升信息宏。你需要:BOOST_VERSION
回答by Vertexwahn
Tested with boost 1.51.0:
使用 boost 1.51.0 测试:
std::cout << "Using Boost "
<< BOOST_VERSION / 100000 << "." // major version
<< BOOST_VERSION / 100 % 1000 << "." // minor version
<< BOOST_VERSION % 100 // patch level
<< std::endl;
Output: Using Boost 1.51.0
输出:使用 Boost 1.51.0
Tested with boost versions 1.51.0 to 1.65.0
使用 boost 版本 1.51.0 到 1.65.0 进行测试
回答by user1245262
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
如果你只需要了解自己的信息,直接查看/usr/include/boost/version.hpp(Ubuntu 13.10)中的信息即可
回答by hkaiser
#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.
更新:答案已修复。
回答by P-M
Depending on how you have installed boost and what OS you are running you could also try the following:
根据您安装 boost 的方式以及您运行的操作系统,您还可以尝试以下操作:
dpkg -s libboost-dev | grep 'Version'
回答by Kamil S Jaron
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).
使用自制软件安装在 OS X 上的 Boost 具有所需的version.hpp
文件/usr/local/Cellar/boost/<version>/include/boost/version.hpp
(注意,该版本已在路径中提及)。
I guess the fastest way to determine version on any UNIX-like system will be to search for boost
in /usr
:
我想在任何类 UNIX 系统上确定版本的最快方法是搜索boost
in /usr
:
find /usr -name "boost"
find /usr -name "boost"
回答by Jayhello
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)):
对我来说,你可以先(找到 version.hpp 中的版本变量,如果你知道它在哪里(在 ubuntu 中,它通常在/usr/include/boost/version.hpp
默认情况下安装)):
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"
回答by artm
Another way to get current boost version (Linux Ubuntu):
获取当前增强版本的另一种方法(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
参考:https: //www.oset.com/en/how-to-install-boost-on-ubuntu-16-04-18-04-linux.html
回答by JulianW
I stugeled to find out the boost version number in bash.
我努力找出bash 中的 boost 版本号。
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)
最终执行以下操作,将版本代码存储在变量中,以抑制错误。这在已接受答案的评论中使用了来自 maxschlepzig 的示例。(不能评论,没有 50 代表)
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.
我知道很久以前就已经回答了这个问题。但是我在任何地方都找不到如何在 bash 中做到这一点。所以我认为这可能会帮助有同样问题的人。此外,无论 boost 安装在哪里,只要编译器可以找到它,这都应该有效。当您安装了多个版本时,它将为您提供编译器实际使用的版本号。
{
VERS=$(echo -e '#include <boost/version.hpp>\nBOOST_VERSION' | gcc -s -x c++ -E - | grep "^[^#;]")
} &> /dev/null
回答by Haresh Karnan
Might be already answered, but you can try this simple program to determine if and what installation of boost you have :
可能已经回答了,但是您可以尝试这个简单的程序来确定您是否安装了 boost 以及安装了什么:
#include<boost/version.hpp>
#include<iostream>
using namespace std;
int main()
{
cout<<BOOST_VERSION<<endl;
return 0;
}