Ara*_*raK 90
提升信息宏.你需要:BOOST_VERSION
Ver*_*ahn 66
使用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;
Run Code Online (Sandbox Code Playgroud)
输出:使用Boost 1.51.0
使用升级版1.51.0至1.65.0进行测试
hka*_*ser 41
#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;
}
Run Code Online (Sandbox Code Playgroud)
更新:答案已得到修复.
P-M*_*P-M 11
根据您安装boost的方式以及运行的操作系统,您还可以尝试以下操作:
dpkg -s libboost-dev | grep 'Version'
Run Code Online (Sandbox Code Playgroud)
使用自制软件安装在OS X上的Boost中包含所需的version.hpp
文件/usr/local/Cellar/boost/<version>/include/boost/version.hpp
(请注意,该路径已在路径中提到)。
我想,以确定任何UNIX类系统上的版本将是搜索的最快方法boost
中/usr
:
find /usr -name "boost"
对我来说,你可以先(找到 version.hpp 中的版本变量,如果你知道它在哪里(在 ubuntu 中,它通常在/usr/include/boost/version.hpp
默认情况下安装)):
locate `boost/version.hpp`
Run Code Online (Sandbox Code Playgroud)
第二个显示它的版本:
grep BOOST_LIB_VERSION /usr/include/boost/version.hpp
Run Code Online (Sandbox Code Playgroud)
或者
grep BOOST_VERSION /usr/include/boost/version.hpp.
Run Code Online (Sandbox Code Playgroud)
对我来说,我的系统中安装了两个版本提升。输出如下:
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"
Run Code Online (Sandbox Code Playgroud)
显示本地安装的版本:
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"
Run Code Online (Sandbox Code Playgroud)
@Vertexwahns 答案,但用 bash 编写。对于懒惰的人:
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)"
Run Code Online (Sandbox Code Playgroud)
给我installed boost version: 1.71.0
小智 5
我努力找出bash 中的 boost 版本号。
最终执行以下操作,将版本代码存储在变量中,以抑制错误。这在已接受答案的评论中使用了来自 maxschlepzig 的示例。(不能评论,没有 50 代表)
我知道很久以前就已经回答了这个问题。但是我在任何地方都找不到如何在 bash 中做到这一点。所以我认为这可能会帮助有同样问题的人。此外,无论 boost 安装在哪里,只要编译器可以找到它,这都应该有效。当您安装了多个版本时,它将为您提供编译器实际使用的版本号。
{
VERS=$(echo -e '#include <boost/version.hpp>\nBOOST_VERSION' | gcc -s -x c++ -E - | grep "^[^#;]")
} &> /dev/null
Run Code Online (Sandbox Code Playgroud)