当前位置: 首页 > article >正文

C++:Boost的安装和使用

1、Boost简介

Boost的本质就是一个开源C++库,它包含多种功能强大的模块,如:字符串文本处理模块、容器、算法、多线程、智能指针、线程池等模块

2、Boost的下载和安装

(1)Boost下载

官网:http://www.boost.org/
SourceForge:C++ Boost Library在国内能够实现更快速的下载

在这里插入图片描述
在这里插入图片描述
window系统下载.zip或.7z;Linux系统下在.gz或.bz2
在这里插入图片描述

(2)Boost安装(Vistual Studio 2022)

由于本机安装的是VS2022,下载的boost版本是boost_1_86_0版本;下载解压后目录如下:
在这里插入图片描述
请确保你的Window系统安装了C++编译器,如MSVC(安装了Vistual Studio默认安装了MSVC编译器)、GCC(安装MinGW)等;然后双击bootstrap.bat(Linux下运行bootstrap.sh);这一阶段会构建Boost的系统环境,并生成一个b2.exe
在这里插入图片描述
运行b2.exe可执行文件,会自动生成两个目录到当前目录,它们分别是bin.v2和stage,其中bin.v2是生成的中间结果,可以直接删除,stage文件夹下包含编译生成的静态库

(3)在VS中配置Boost

配置包含目录
在这里插入图片描述
配置库文件
在这里插入图片描述
配置链接器的附加库目录

配置附加库目录的目的是:指定链接器在链接阶段查找库文件的搜索路径

在这里插入图片描述

(4)测试Boost库是否安装成功

#define BOOST_TIMER_ENABLE_DEPRECATED
#include <boost/timer.hpp>
#include <boost/progress.hpp>
#include <libs/date_time/src/gregorian/greg_names.hpp>
#include <libs/date_time/src/gregorian/greg_month.cpp>
#include <libs/date_time/src/gregorian/gregorian_types.cpp>
#include <boost/date_time/posix_time/posix_time.hpp>
void test_boost_install() {
	boost::timer t;
	boost::gregorian::date dt(1978, 12, 18); //date_time 库
	assert(dt.year() == 1978);
	assert(dt.day() == 18);
	boost::gregorian::date::ymd_type ymd = dt.year_month_day();
	std::cout << "\n" << ymd.year << "/" << ymd.month << "/" << ymd.day << " the day is "
		<< dt.day_of_year() << " days of this year" << std::endl;

	std::cout << boost::gregorian::to_iso_extended_string(dt) << std::endl; //转换为其他格式
	std::cout << boost::gregorian::to_iso_string(dt) << std::endl;
	std::cout << boost::gregorian::to_simple_string(dt) << std::endl << std::endl;
	std::cout << t.elapsed() << "s" << std::endl; //程序运行时间
	system("pause");

}

http://www.kler.cn/news/358029.html

相关文章:

  • 新程序员必备的5个VS Code插件
  • 第6篇:无线与移动网络
  • YOLOv8实战火焰检测【数据集+YOLOv8模型+源码+PyQt5界面】
  • AutoSar AP CM通信组总结
  • 【论文速看】DL最新进展20241020-Transformer量化加速、低光增强
  • 站点中山国际人才网岗位采集练习https://www.job001.cn
  • 基于jsp+mysql+Spring的SpringBoot招聘网站项目
  • Rhymes AI发布首款开源多模态AI模型Aria 性能超越GPT-4o mini等多家知名AI模型
  • SpringBoot框架下的汽车票在线预订系统
  • 【计算机网络 - 基础问题】每日 3 题(五十)
  • dockerfile发布flask程序
  • 【VUE3】子组件中的el-upload 选择图片点击取消 会触发父组件emit cancel方法
  • 点餐小程序实战教程20广告管理
  • Redis数据持久化机制详解
  • vite server正则表达式
  • 各种查询sql介绍
  • 重学SpringBoot3-集成Spring Security(一)
  • 进程间通信——管道
  • ts 中 type 和 interface 的区别
  • 2024CSP-J模拟赛9————S12678