Boost asio install linux

How to install Boost on Ubuntu

find packages you need and install them using the apt-get command.

I had programming experience with boost, but not installation experience. I have never tried this myself, so I can’t say if it is easy to use (but it seems to me that package manager is the easiest way). I should have posted this suggestion as a comment, but I can’t comment questions.

The one disadvantage of using apt-get is that it is usually a couple of version behind the latest boost release.

It is easy to build and install Boost from the sources, for example anycoder.wordpress.com/2014/04/28/building-boost

Do not use the packaged version of boost, right now on Ubuntu 16.04 it’s 1.58, and the latest stable version is 1.67.0 ! See the response and my comment below : stackoverflow.com/a/41272796/2617716

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

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:

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

and eventually install it:

What will be the difference if we use ./bootstrap.sh —prefix=/usr/include ? I have the boost library in /usr/include. I was wondering that by doing this, can I replace my old installation ?

@tbc0 Boost is at version 1.59 now, and the latest PPA is at 1.55, so building from source is relevant

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

Install libboost-all-dev and aptitude:

sudo apt install libboost-all-dev sudo apt install aptitude aptitude search boost 

Then paste this into a C++ file called main.cpp :

#include #include using namespace std; int main() < boost::arrayarr = >; cout

adding »

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

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:

sudo apt-get update sudo apt-get install build-essential g++ python-dev autotools-dev libicu-dev libbz2-dev
./bootstrap.sh --prefix=/usr/local

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

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 ''`

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:

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

Some things such as PO Edit 2.0 require boost 1.6, which is not available at this time via apt-get you can get this from boost.org/users/history/version_1_60_0.html and then expand it. Follow the excellent instructions above, remembering that LD Library Path is not the same as $PATH

Читайте также:  Print file size in linux

Comment from a recent installation, to get the latest version : — Go to boost.org and «Current release» downloads to get the last one (currently 1.67.0 : dl.bintray.com/boostorg/release/1.67.0/source/…) Thanks !

old link to sourceforge is not working. use dl.bintray.com/boostorg/release/1.72.0/source/… (with needed version)

An update for Windows 10 Ubuntu Application via Subsystem (also works on standard Ubuntu):

You might have problems finding the package. If you do, never fear! PPA is here!

sudo add-apt-repository ppa:boost-latest/ppa sudo apt-get update 
sudo apt-get install libboost-all-dev 

I’m aware, posting for those (Like me) who were looking for a rounded solution. Similar to Алексей Штыков’s Answer

@AdrianW this answer isn’t about Windows 10. It’s about Ubuntu that happens to be running on a Windows 10 kernel, so it’s a valid solution to those running Ubuntu in some way. Since the question didn’t limit it to Ubuntu running on a Linux kernel specifically, this solution is fine.

The repository ‘ppa.launchpad.net/boost-latest/ppa/ubuntu xenial Release’ does not have a Release file.

I am having following erro: E: The repository ‘http://ppa.launchpad.net/boost-latest/ppa/ubuntu focal Release’ does not have a Release file.

You can install boost on ubuntu by using the following commands:

sudo apt install libboost-all-dev

$ sudo apt-get install libboost* 

You may get an error message similar to the following, like I did:

E: Unable to correct problems, you have held broken packages. 

Then try install below package:

$ sudo apt-get install libboost-all-dev 

Now you can create a a sample project utilizing Boost:

$ mkdir boost $ cd boost/ $ cat > main.cpp & 

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/ .

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 .

This would only work for header libraries of boost. The rest of them would need to be built or installed using a package manager as described in the above answers. The boost libraries that require separate building and installation are the following: atomic, chrono, container, context, coroutine, coroutine2, date_time, exception, filesystem, graph, graph_parallel, iostreams, locale, log, math, mpi, program_options, python, random, regex, serialization, signals, system, test, thread, timer, type_erasure, wave.

Even repairing this solution by following Elias Kouskoumvekakis’s further instructions would be a bad idea (unless you have a good reason), since package managers add the ability to very easily update Boost to newer versions (in Ubuntu, just a sudo apt update; sudo apt upgrade to upgrade all your packages to the latest versions in the repositories) if you find the appropriate package repository for Boost and to very easily delete Boost from the system if you want to. The manual approach makes those tasks harder, so you need a good reason to skip out on the benefits of a package manager.

Читайте также:  Spoof with kali linux

Also, installing without a package manager is better covered in an earlier answer, which includes necessary building instructions.

Источник

How to Install the Boost Library in C++ on Ubuntu or any other Linux Distribution

Boost is a portable set of C++ programming language libraries. It contains libraries for pseudo-random number generation, linear algebra, multi-threading, image processing, regular expressions, and unit testing.

At the time of writing this article, Boost has 168 different libraries, which are getting increased regularly with new additions and updates.

According to the C++ Coding Standards book, it is considered “one of the most highly regarded and expertly designed C++ library projects in the world.”

So, let me show you how you can install the Boost library in Ubuntu or any other Debian-based distribution, but before that, let me list some of the libraries that you will find in Boost.

List of Libraries are avaible for use

Here, I have listed some of the libraries that you will be able to use once you install the Boost library on your Linux machine, such as:

  • Boost.Asio: Use for networking and other low-level I/O operation
  • Boost.Beast: Portable HTTP, WebSocket, and network operations
  • Boost.Coroutine2: Coroutine library for Asynchronous
  • Boost.GIL: Generic image library provide an easy way to read and write image
  • Boost.Lambda: Flexible way to define unamed function objects
  • Boost.Polygon: Helpful in geometric operations
  • Boost.Python: Interoperability between C++ and Python
  • Boost.Math: It’s allow you to perform various mathemical operation easily
  • Boost.Serialization: Serializing and de-serializing C++ Objects
  • Boost.JSON: JSON Parsing and Serializing
  • Boost.URL: For URL parsing
  • Boost.Xpressive: Regular expressions that can be written as strings or as expression templates

If you want to know what all libraries are available, then you can click here to find out.

Install Boost Library in C++

The Boost library can be installed on your Ubuntu machine in a couple of ways.

One of them is to install it from the system repository, and the second option is to download and install the package from the source, or else you can use the source file as a portable library.

Both methods have their own advantages.

If you are considering the first method, then you will not find the latest version of the library, but the installation will be simple and less time-consuming.

If you don’t care about the latest release, then you can choose the first option, and those who want to use the latest version of Boost in their system can use the source method to install Boost libraries which requires some additional steps.

Install Boost library from Ubuntu System Repository

To start the installation, run the below command into your terminal and wait for the process to complete.

$ sudo apt install libboost-all-dev

Install boost library from repo

Once the installation is complete, you can use the library in your project.

Читайте также:  Сколько весит убунту линукс

Install Boost Library from the Source Package for all Linux Distributions

With the above method, you can get the Boost library installed on your Ubuntu machine, but the version will be older compared to this one, and the second thing is that this method will work on all Linux systems without any issue.

So, let me get into step straight away to show how to install Boost in linux.

First of all, you will require the latest release of Boost from the official page, or you can also get a Boost from the Github release section of Boost.

Once the pages get loaded, click on “Download”, which redirects you to the index page, and from there, you can get libraries in different compressions.

Download latest version of Boost library

At the time of writing, this instruction’s latest version is 1.81.0. I’m downloading boost_1_79_0.tar.gz for this article. If you want, you can go with other compressed files too.

Select the compressed version of Boost 1.79.0

Once the file is downloaded, go to the directory where the file is located and extract it using the below command if you have downloaded boost_1_81_0_.tar.gz.

$ tar xvf boost_1_81_0.tar.gz 

After that, you can use these libraries as portable with your project, so just make sure to remember the path where you have extracted the libraries.

And if you want to install libraries system-wide, then pass the following command to the terminal and specify the library directory in your programme file to prevent errors.

./bootstrap.sh --prefix=/usr/ ./b2 sudo ./b2 install

Demo Sample

Once you are done with the above procedure, you can test the library’s functionality with the sample programme. You can copy-paste the code snippet from here and save it as example.cpp.

#include  // Remove this line if you are using portable library #include #include #include #include int main() < using namespace boost::lambda; typedef std::istream_iteratorin; std::for_each( in(std::cin), in(), std::cout 

I’m assuming you are using the g++ for compilation.

Then go to the directory where example.cpp is located and run the following command:

$ g++ example.cpp -o sample

If you are using portable libraries, then you need to run the below command:

$ g++ -I /path/boost_1_79_0 example.cpp -o sample

Once the programme is compiled successfully, you can test out the output.

$ ./sample 1 3 2 6 3 9

Wrap up

That’s all for this guide, where you learned how to install the Boost library for C++ in Ubuntu and other Linux distributions.

I think you have installed the Boost successfully, but if you are facing any problems with the steps, then do let us know in the comment section.

Bye..Bye.. We will meet soon in the next article.

A man with a tech effusive who has explored some of the amazing technology stuff and is exploring more. While moving towards, I had a chance to work on Android development, Linux, AWS, and DevOps with several open-source tools.

Источник

Оцените статью
Adblock
detector