Build and install the Boost library under Linux

Source: Internet
Author: User
Tags bz2

Reprint: http://www.cnblogs.com/oloroso/p/4632848.html

Build and install the Boost library under Linux
    • Build and install the Boost library under Linux
      • 1. Download and unzip the boost 1.58 source code
        • Download
        • Extract
      • 2. Running bootstrap.sh
      • 3, using B2 to build
        • Tips for building success
      • 4. Install the boost library to the specified directory
      • 5, test
        • Code
        • Compile run

Check the system environment first

Linux o-pc 3.19.0-22-generic #22-Ubuntu SMP Tue Jun 16 17:15:15 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

This article by Mob Lym fabricated, welcome reprintblog.cnblogs.net/oloroso
This article by Mob Lym fabricated, welcome reprintmy.oschina.net/oloroso

1. Download and unzip the boost 1.58 source code

can go to boost the official website to download, here provides a

Download
wget http://jaist.dl.sourceforge.net/project/boost/boost/1.58.0/boost_1_58_0.tar.bz2
Extract
tar -xjf boost_1_58_0.tar.bz2
2. Operation bootstrap.sh

bootstrap.shis used to check the installation environment, if the error, look at what is missing, install can ( g++ ).

./bootstrap.sh

After the run completes, some files are generated in the current directory for the next installation.

3. Use b2To build

b2is generated after the success of the previous step, use it to build the boost library.

sudo ./b2

You may also encounter errors here, such as without bzlib.h this header file.

cc.compile.c++ bin.v2/libs/iostreams/build/gcc-4.9.2/release/link-static/threading-multi/bzip2.olibs/iostreams/src/bzip2.cpp:20:56: fatal error: bzlib.h: 没有那个文件或目录 #include "bzlib.h"  // Julian Seward‘s "bzip.h" header.                                                        ^compilation terminated.

The workaround is also very simple, execute the following statement (provided that the Linux distribution of the Debina system is installed apt-get )

Tips for building success
The Boost C++ Libraries were successfully built!The following directory should be added to compiler include paths:    /home/o/Boost库/boost_1_58_0The following directory should be added to linker library paths:    /home/o/Boost库/boost_1_58_0/stage/lib

The above sentence means that you are prompted to compile the boost include directory and directory location that you specified when using the library's code lib .

4. Install the boost library to the specified directory

The third step is just to say the construction of the situation, in fact, this can be used. If you want boost to install the library to a specific directory, such as a usr/local directory, you can use the following command.

sudo ./b2 --prefix=/usr/local/boost install

If you want to specify a directory when you compile the code later, you can add it to the environment variable CPLUS_INCLUDE_PATH and to LIBRARY_PATH the.

export CPLUS_INCLUDE_PATH=/usr/local/boost/includeexport LIBRARY_PATH=/usr/local/boost/lib

This is only temporary and is happy to be written /etc/profile in the file.

5, test

Start by writing a simple applet that gets the current date

Code
#include <boost/date_time/gregorian/gregorian.hpp> #include <iostream> int main() {     boost::gregorian::date d(boost::gregorian::day_clock::local_day());    std::cout << d.year() << d.month() <<d.day() << std::endl; }
Compile run
g++ -I /usr/local/boost/include -L /usr/local/boost/lib boost.cpp -o boost ./boost 2015Jul9

Build and install the Boost library under Linux

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.