C++Boost的使用

下载

到Boost官网下载

安装

运行 bootstrap.bat(Win) boostrap.sh(Linux),会在当前目录下生成一个 b2.exe ,然后在命令行输入b2 --build .以及b2 --install .将boost库安装到默认目录下,Windows是C:\\

使用

CMake配置Boost

cmake_minimum_required (VERSION 3.8)

set(target_name "boost_test")

#指定boost根目录
set(BOOST_ROOT "C:/Boost")
#设置不适用系统的的boost的库
set(BOOST_NO_SYSTEM_PATHS ON)
#设置使用静态的boost库
set(Boost_USE_STATIC_LIBS ON)
#查找boost库
find_package(Boost REQUIRED)

add_executable (${target_name} "main.cpp")
include_directories(${Boost_INCLUDE_DIRS})
link_directories(${Boost_LIBRARY_DIRS})
target_link_libraries (${target_name} ${Boost_LIBRARIES})

C++测试代码

#include <boost/array.hpp>
#include <iostream>

int main()
{
	boost::array<int, 2> test{ 11,22 };

	std::cout << test.at(0) << ',' << test[1] << '\n';

	system("pause");
}
posted @ 2022-05-26 09:12  滴哒哒哒  阅读(376)  评论(0编辑  收藏  举报