参考文章:https://blog.csdn.net/qq_36666115/article/details/131015894
1)安装开发者工具
我们需要工具从其源代码构建 Boost 库,这里是获取所需库的命令: sudo apt-get install build-essential g++ python3-dev autotools-dev libicu-dev libbz2-dev libboost-all-dev2)下载需要版本的boost代码包
网址:Boost Version History3)提取Tar文件
tar xvf boost_1_80_0.tar.gz
cd boost_1_80_0
4)设置Boost的bootstrap
之后运行给定的命令,该命令将启动存在于 Boost 提取文件夹中的 Bootstrap 脚本。它将开始构建 B2 引擎。另外,它会将编译后的库文件保存在/usr/include/boost./bootstrap.sh --prefix=/usr/
5)在 Ubuntu 20.04 或 22.04 上安装 Boost
构建 Boost C++ 库 构建完 b2 引擎后,您将在 Boost 目录中看到一个名为b2的可执行文件。我们必须运行它来开始构建 Boost C++ 库。sudo ./b2 install
6)在C++编程中使用Boost库
现在,无论何时你想使用或包含 Boost 库开始编码,你只需要包含你想使用的 Boost 库的名称。 例如,如果你想使用geometry库: #include <iostream>#include <boost/geometry.hpp> #include <boost/geometry/geometries/point_xy.hpp> #include <boost/geometry/geometries/polygon.hpp>
namespace bg = boost::geometry;
int main() { // Checks if the two geometries overlaps or not. bg::model::polygon<bg::model::d2::point_xy<double> > poly1; bg::read_wkt("POLYGON((0 0,1 1,0 1,0.1 0.2))", poly1); bg::model::polygon<bg::model::d2::point_xy<double> > poly2; bg::read_wkt("POLYGON((2 2,2 6,6 7,6 1,2 2))", poly2); bool check_overlap = bg::overlaps(poly1, poly2); if (check_overlap) { std::cout << "Overlaps: Yes" << std::endl; } else { std::cout << "Overlaps: No" << std::endl; }
bg::model::polygon<bg::model::d2::point_xy<double> > poly3; bg::read_wkt("POLYGON((-1 -1,-3 -4,-7 -7,-4 -3,-1 -1))", poly3); check_overlap = bg::overlaps(poly1, poly3); if (check_overlap) { std::cout << "Overlaps: Yes" << std::endl; } else { std::cout << "Overlaps: No" << std::endl; }
return 0; }