CentOS 7 under Compile Boost_1_57_0

Source: Internet
Author: User
Tags regex expression

The previous understanding of the library is too superficial (and now still very superficial), leading to a lot of detours, is now recorded for later investigation.

You can now download from the Boost website to the latest boost source code boost_1_57_0.tar.gz.

The steps are now documented as follows:

1. Unzip (non-root)
$tar-XF boost_1_57_0.tar.gz
2. Execute bootstrap.sh (non-root)
$CD boost_1_57_0$./bootstrap.sh
3. Compile (non-root):./B2 parameters

This is not said to compile the installation , because in the non-root account, the compilation of the installation process generated by the various library files are not put in the /usr/local/ directory.

The default compilation parameters are saved under Project-config.jam and can be viewed by VIM itself.

  The ./b2 has many parameters to choose from, as follows (./B2--help):

  

In this case, I will choose a simple parameter:

$./B2--without-python Stage Debug

The compilation time will be longer, and the build will generate the Boost directory (header file), Stage/lib directory (dynamic library and Static library).

4. Copy of header file and library file: sudo cp src_dir Des_dir

Copy the generated boost directory to/usr/include/and copy all the files under stage/lib/to/usr/lib64/, as follows:

$sudo cp-rf boost/usr/include$sudo cp-rf stage/lib/*/usr/lib64
5. Testing

Test file Test.cpp:

1#include <iostream>2#include <string>3#include <boost/regex.hpp>4 5 intMain ()6 {7STD::stringstr ="192.168.1.1";8 9Boost::regex expression ("([0-9]+). ([0-9]+). ([0-9]+)");Ten Boost::smatch what; One  A     if(Boost::regex_search (str, what, expression)) -     { -Std::cout << what.size () <<Std::endl; the          for(size_t i =0; I < what.size (); i++) -         { -             if(what[i].matched) -             { +Std::cout << What[i] <<Std::endl; -             } +         } A     } at  -     return 0; -}
View Code

Makefile:

inc_dir=-i/usr/include/lib_dir=-l/usr/lib64/lib=-lboost_regexcc=g++-gcflags=-wallexe=testall:$ (CC) $ (CFLAGS) $ ( EXE). Cpp-o $ (EXE) $ (inc_dir) $ (lib_dir) $ (LIB) CLEAN:RM-RF *.o $ (EXE)
View Code6. Install the boost library somewhere else

We may not be willing to install the boost library directly into the/usr/directory, but/usr/local/.

$sudo Mkdir/usr/local/boost_1_57_0$sudo Mkdir/usr/local/boost_1_57_0/include$sudo mkdir/usr/local/boost_1_57_0/ Lib64$sudo cp-rf boost/usr/local/boost_1_57_0/include$sudo cp-rf stage/lib/*/usr/local/boost_1_57_0/lib64

Because it is not installed by default in the/lib or/usr/lib directory, you need to modify the next/etc/ld.so.cache file to add the new library directory/usr/local/boost_1_57_0/lib64 to the/etc/ Ld.so.cache file, the steps are as follows:

A) Edit the/etc/ld.so.conf file and add the path to the directory where the library file resides

/usr/local/boost_1_57_0/lib64/

b) Run Ldconfig and the command rebuilds the/etc/ld.so.cache file

In addition, the corresponding makefile at the time of writing the header file directory and library directory should be changed to:

inc_dir=-i/usr/local/boost_1_57_0/include/lib_dir=-l/usr/local/boost_1_57_0/lib64/
7. Boost Library "Uninstall"

Since we simply copy the header and library files, we can delete the Boost library header and library files directly, as follows:

$sudo Rm-rf/usr/include/boost$sudo rm/usr/lib64/*boost*
8. PostScript

I adopt a relatively cumbersome approach, preferably of course, the direct "sudo./B2 parameter". Let's see what everyone needs.

CentOS 7 under Compile Boost_1_57_0

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.