Boost1.7.4源码编译
最近想把ORB_SLAM3在windows上编译运行,因为最新的的ORB_Slam3需要用到Boost这个库,因此将Boost库的编译过程记录下来。
一、下载
到官网下载:下载地址
二、解压
三、利用VS cmd进行编译
打开vs2019的 x86_x64 Cross Tools Command Prompt for VS工具
然后运行以下命令(我的boost解压路径为E:\App_Lib\boost_1_74_0,根据自己的路径进行修改)
cd \
E:
cd E:\App_Lib\boost_1_74_0
bootstrap.bat
然后执行命令
.\b2.exe
四、VS新建项目测试编译好的Boost库
在项目属性->所有选项->附加包目录->选择以下目录添加(依赖项和头文件)
E:\App_Lib\boost_1_74_0
E:\App_Lib\boost_1_74_0\stage\lib
五、测试代码
测试代码1
#include <boost/lexical_cast.hpp>
#include <iostream>
using namespace std;
using namespace boost;
int main()
{
//system("chcp 65001");
double a = lexical_cast<double>("3.1415926");
string str = lexical_cast<string>("3.1415926");
cout << "This is a number: " << a << endl;
cout << "This is a string: " << str << endl;
int b = 0;
try {
b = lexical_cast<int>("neo");
}
catch (bad_lexical_cast& e) {
cout << e.what() << endl;
}
return 0;
}
测试代码2
#include <iostream>
#include <boost/sort/sort.hpp>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{
vector<int> arr;
while (arr.size() < 100) arr.push_back(std::rand());
boost::sort::block_indirect_sort(std::begin(arr), std::end(arr));
for_each(std::begin(arr), std::end(arr), [](int& a) {
cout << a << "\t";
});
return 0;
}