如何在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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章