如何在Ubuntu上安装Boost

本文翻译自:How to install Boost on Ubuntu

I'm on Ubuntu, and I want to install Boost. 我在Ubuntu上,并且想安装Boost。 I tried with 我尝试过

sudo apt-get install boost

But there was no such package. 但是没有这样的软件包。 What is the best way to install Boost on Ubuntu? 在Ubuntu上安装Boost的最佳方法是什么?


#1楼

参考:https://stackoom.com/question/qmF1/如何在Ubuntu上安装Boost


#2楼

You can use apt-get command (requires sudo ) 您可以使用apt-get命令(需要sudo

sudo apt-get install libboost-all-dev

Or you can call 或者你可以打电话

aptitude search boost

find packages you need and install them using the apt-get command. 查找所需的软件包并使用apt-get命令安装它们。


#3楼

Installing Boost on Ubuntu with an example of using boost::array : 以使用boost::array的示例在Ubuntu上安装Boost:

Install libboost-all-dev and aptitude: 安装libboost-all-dev和aptitude:

sudo apt install libboost-all-dev

sudo apt install aptitude

aptitude search boost

Then paste this into a C++ file called main.cpp : 然后将其粘贴到一个名为main.cpp的C ++文件中:

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

using namespace std;
int main(){
  boost::array<int, 4> arr = {{1,2,3,4}};
  cout << "hi" << arr[0];
  return 0;
}

Compile like this: 像这样编译:

g++ -o s main.cpp

Run it like this: 像这样运行它:

./s

Program prints: 程序打印:

hi1

#4楼

Get the version of Boost that you require. 获取所需的Boost版本。 This is for 1.55 but feel free to change or manually download yourself: 这是1.55,但可以随时更改或手动下载:

wget -O boost_1_55_0.tar.gz https://sourceforge.net/projects/boost/files/boost/1.55.0/boost_1_55_0.tar.gz/download
tar xzvf boost_1_55_0.tar.gz
cd boost_1_55_0/

Get the required libraries, main ones are icu for boost::regex support: 获得所需的库,主要的是icu以获取boost::regex支持:

sudo apt-get update
sudo apt-get install build-essential g++ python-dev autotools-dev libicu-dev build-essential libbz2-dev libboost-all-dev

Boost's bootstrap setup: Boost的引导程序设置:

./bootstrap.sh --prefix=/usr/

Then build it with: 然后用:

./b2

and eventually install it: 并最终安装它:

sudo ./b2 install

#5楼

Actually you don't need "install" or "compile" anything before using Boost in your project. 实际上,在项目中使用Boost之前,您不需要“安装”或“编译”任何内容。 You can just download and extract the Boost library to any location on your machine, which is usually like /usr/local/ . 您可以将Boost库下载并解压缩到计算机上的任何位置,通常类似于/usr/local/

When you compile your code, you can just indicate the compiler where to find the libraries by -I . 编译代码时,您可以通过-I指示编译器在何处查找库。 For example, g++ -I /usr/local/boost_1_59_0 xxx.hpp . 例如, g++ -I /usr/local/boost_1_59_0 xxx.hpp


#6楼

Get the version of Boost that you require. 获取所需的Boost版本。 This is for 1.55 but feel free to change or manually download yourself: 这是1.55,但可以随时更改或手动下载:

wget -O boost_1_55_0.tar.gz http://sourceforge.net/projects/boost/files/boost/1.55.0/boost_1_55_0.tar.gz/download
tar xzvf boost_1_55_0.tar.gz
cd boost_1_55_0/

Get the required libraries, main ones are icu for boost::regex support: 获得所需的库,主要的是icu以获取boost :: regex支持:

sudo apt-get update
sudo apt-get install build-essential g++ python-dev autotools-dev libicu-dev libbz2-dev

Boost's bootstrap setup: Boost的引导程序设置:

./bootstrap.sh --prefix=/usr/local

If we want MPI then we need to set the flag in the user-config.jam file: 如果我们需要MPI,则需要在user-config.jam文件中设置标志:

user_configFile=`find $PWD -name user-config.jam`
echo "using mpi ;" >> $user_configFile

Find the maximum number of physical cores: 查找最大物理核数:

n=`cat /proc/cpuinfo | grep "cpu cores" | uniq | awk '{print $NF}'`

Install boost in parallel: 并行安装boost:

sudo ./b2 --with=all -j $n install

Assumes you have /usr/local/lib setup already. 假设您已经设置了/ usr / local / lib if not, you can add it to your LD LIBRARY PATH : 如果没有,您可以将其添加到LD LIBRARY PATH中

sudo sh -c 'echo "/usr/local/lib" >> /etc/ld.so.conf.d/local.conf'

Reset the ldconfig: 重置ldconfig:

sudo ldconfig
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章