如何在Ubuntu上安装boost ?

时间:2022-09-09 07:35:27

I'm on Ubuntu, and I want to install Boost. I tried with

我在Ubuntu上,我想安装Boost。我试着用

sudo apt-get install boost

But there was no such package. What is the best way to install boost on Ubuntu?

但并没有这样的计划。在Ubuntu上安装boost的最好方法是什么?

6 个解决方案

#1


574  

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命令安装它们。

#2


115  

Get the version of Boost that you require. This is for 1.55 but feel free to change or manually download yourself:

获得您需要的Boost版本。这是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支持::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:

提高的引导设置:

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

Then build it with:

然后构建:

./b2

and eventually install it:

并最终将其安装:

sudo ./b2 install 

#3


59  

Installing Boost on Ubuntu with an example of using boost array:

使用Boost阵列的示例在Ubuntu上安装Boost:

Install libboost-all-dev and aptitude

安装libboost-all-dev和资质

sudo apt-get install libboost-all-dev

sudo apt-get 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


8  

Get the version of Boost that you require. This is for 1.55 but feel free to change or manually download yourself:

获得您需要的Boost版本。这是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支持::regex支持:

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

Boost's bootstrap setup:

提高的引导设置:

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

If we want MPI then we need to set the flag in the user-config.jam file:

如果我们想要MPI,那么我们需要在用户配置中设置标志。果酱文件:

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:

安装提高并行:

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

Assumes you have /usr/local/lib setup already. if not, you can add it to your LD LIBRARY PATH:

假设您已经有/usr/local/lib设置。如果没有,您可以将其添加到您的LD库路径:

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

Reset the ldconfig:

重置ldconfig:

sudo ldconfig

#5


0  

Actually you don`t need "install" or "compile" anything before using boost in your project. You can just download and extract the boost library to any location on your machine, which is usually like /usr/local/.

实际上,在您的项目使用boost之前,您不需要“安装”或“编译”任何东西。您可以下载并提取boost库到您的机器上的任何位置,通常是/usr/local/。

When you compile your code, you can just indicate the compiler where to find the libraries by -I. For example, g++ -I /usr/local/boost_1_59_0 xxx.hpp

当您编译代码时,您可以指示编译器在哪里找到我的库。例如,g++ -I /usr/local/boost _1_ 59_0 xxx.hpp。

Hope this helps.

希望这个有帮助。

#6


0  

For Windows 10 Ubuntu application:

Windows 10 Ubuntu应用程序:

sudo apt-get install libboost-all-dev

#1


574  

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命令安装它们。

#2


115  

Get the version of Boost that you require. This is for 1.55 but feel free to change or manually download yourself:

获得您需要的Boost版本。这是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支持::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:

提高的引导设置:

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

Then build it with:

然后构建:

./b2

and eventually install it:

并最终将其安装:

sudo ./b2 install 

#3


59  

Installing Boost on Ubuntu with an example of using boost array:

使用Boost阵列的示例在Ubuntu上安装Boost:

Install libboost-all-dev and aptitude

安装libboost-all-dev和资质

sudo apt-get install libboost-all-dev

sudo apt-get 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


8  

Get the version of Boost that you require. This is for 1.55 but feel free to change or manually download yourself:

获得您需要的Boost版本。这是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支持::regex支持:

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

Boost's bootstrap setup:

提高的引导设置:

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

If we want MPI then we need to set the flag in the user-config.jam file:

如果我们想要MPI,那么我们需要在用户配置中设置标志。果酱文件:

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:

安装提高并行:

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

Assumes you have /usr/local/lib setup already. if not, you can add it to your LD LIBRARY PATH:

假设您已经有/usr/local/lib设置。如果没有,您可以将其添加到您的LD库路径:

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

Reset the ldconfig:

重置ldconfig:

sudo ldconfig

#5


0  

Actually you don`t need "install" or "compile" anything before using boost in your project. You can just download and extract the boost library to any location on your machine, which is usually like /usr/local/.

实际上,在您的项目使用boost之前,您不需要“安装”或“编译”任何东西。您可以下载并提取boost库到您的机器上的任何位置,通常是/usr/local/。

When you compile your code, you can just indicate the compiler where to find the libraries by -I. For example, g++ -I /usr/local/boost_1_59_0 xxx.hpp

当您编译代码时,您可以指示编译器在哪里找到我的库。例如,g++ -I /usr/local/boost _1_ 59_0 xxx.hpp。

Hope this helps.

希望这个有帮助。

#6


0  

For Windows 10 Ubuntu application:

Windows 10 Ubuntu应用程序:

sudo apt-get install libboost-all-dev