Boost安装
Nevermore 2023-01-11 LinuxSoftware
Centos7使用sudo yum install boost-devel
默认安装的是1.53版本的,若要使用最新版本则需要去官网下载编译,但编译时常出现错误。这里提供了一种新的安装方式,即使用conda。为了节省服务器资源,考虑使用miniconda。
- 安装
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
1
chmod +x Miniconda3-latest-Linux-x86_64.sh
1
./Miniconda3-latest-Linux-x86_64.sh
1
source ~/.bashrc # 激活 conda deactivate
1
conda --version # 安装成功查看版本
1
conda config --add channels conda-forge # 添加boost源
1
conda install -c conda-forge boost
1
- 配置编译环境
vim ~/.bashrc
1
#添加minicoda 安装的boost路径
export CPLUS_INCLUDE_PATH=/home/z/miniconda3/include/boost:$CPLUS_INCLUDE_PATH
export LIBRARY_PATH=/home/z/miniconda3/lib:$LIBRARY_PATH
1
2
3
2
3
source ~/.bashrc
1
- 配置运行环境
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$LIBRARY_PATH #当前有效
1
echo /home/z/miniconda3/lib > /etc/ld.so.conf.d/boost.conf #永久有效
ldconfig
1
2
2
- 编译添加
#include <boost/filesystem.hpp>
#include <iostream>
int main() {
boost::filesystem::path p("./..");
if(boost::filesystem::exists(p)) {
std::cout << p << " exists." << std::endl;
}
else {
std::cout << p << " does not exist." << std::endl;
}
return 0;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14
test:test.cc
g++ -o $@ $^ -std=c++11 -I/home/z/miniconda3/include -L/home/z/miniconda3/lib/ -lpthread -lboost_filesystem -lboost_system
.PHONY:clean
clean:
rm -rf test
1
2
3
4
5
6
2
3
4
5
6