Http://blog.csdn.net/glt3953/article/details/9960179
Manual download
Http://www.bzip.org/1.0.5/bzip2-1.0.5.tar.gz
Decompress:
Tar -- Bzip2-XF./boost_1_54_0.tar.bz2
Start to compile, all compilation takes too much time, so I only select the library I need:
Run the following command to check how many libraries can be compiled:
./Bootstrap. Sh -- show-libraries
Building boost. Build engine with toolset GCC... tools/build/v2/engine/bin. linuxx86_64/b2
The following boost libraries have portions that require a separate build
And Installation step. Any library not listed here can be used by including
The headers only.
The boost libraries requiring separate building and installation are:
-Atomic
-Chrono
-Context
-Coroutine
-Date_time
-Exception
-Filesystem
-Graph
-Graph_parallel
-Iostreams
-Locale
-Log
-Math
-MPI
-Program_options
-Python
-Random
-RegEx
-Serialization
-Signals
-System
-Test
-Thread
-Timer
-Wave
Then compile the library I want:
./Bootstrap. Sh -- With-libraries = system, filesystem, log, thread
Building boost. Build engine with toolset GCC... tools/build/v2/engine/bin. linuxx86_64/b2
Unicode/ICU support for boost. RegEx ?... Not found.
Generating boost. Build configuration in project-config.jam...
Bootstrapping is done. To build, run:
./B2
To adjust configuration, edit 'project-config. jam '.
Further information:
-Command Line Help:
./B2 -- Help
-Getting Started Guide:
Http://www.boost.org/more/getting_started/unix-variants.html
-Boost. Build documentation:
Http://www.boost.org/boost-build2/doc/html/index.html
Then run the following command to complete the compilation.
./B2
Wait patiently. However, not all libraries are compiled. There will be much less time. Compile later. The result is displayed soon:
The boost C ++ libraries were successfully built!
The following directory shocould be added to compiler include paths:
/Usr/src/boost_000054_0
The following directory shocould be added to linker library paths:
/Usr/src/boost_000054_0/stage/lib
I forgot to install it.Run the./B2 install command, which is installed on
/Usr/local/lib directory
Header file in
/Usr/local/include/Boost directory
**************************************** **************************************** ***************
Preparations: other function libraries are used in boost. To use the functions in boost, you must first install the libraries that may be missing in the system.
apt-get install mpi- default -Dev # Install the MPI Library |
Apt-Get install libicu-dev # Unicode Character Set supporting regular expressions |
Apt-Get install Python-dev # If python is needed |
Apt-Get install libbz2-dev # If compilation error: bzlib. h: no such file or directory appears |
After the above function library is installed, You can compile the boost library. Decompress boost_000049_0.tar.bz2, get/boost_000049_0, and switch the current working directory to this folder.
Generate bjam. The preceding command can have various options. For more information, see./Bootstrap. Sh -- help. The -- prefix parameter can be used to specify the installation path. If the -- prefix parameter is not included (recommended), the default path is/usr/local/include and/usr/local/lib, store header files and various libraries respectively. After execution, bjam is generated, and existing scripts are automatically backed up. Note: boost 1.49 will generate two files bjam and B2 in the current directory. These two files are the same. Therefore, you can use either of the two files to execute the following steps.
using MPI; # If you need the MPI function, you need to add it at the end of the/tools/build/v2/user-config.jam File |
Next, use the generated bjam script to compile the source code.
./B2-a-shave_icu = 1 #-a parameter, which indicates recompilation, and-shave_icu = 1 indicates Unicode/ICU is supported. |
Note: here we compile all. Of course, you can also choose to compile only a part. The option -- With-<library> is used to compile only the specified library. For example, if you enter -- With-RegEx, only the RegEx library is compiled. Boost1.49 is fully compiled. On the author's intel core2 duo CPU t5750 @ 2.00 GHz × 2, 2g DDR2 memory old machine, the above options are used, and it takes about half an hour. This time is tolerable. All compilation and installation are psychologically comfortable. Pai_^
Some common parameters of bjam are listed as follows:
-- Build-Dir = <builddir> |
The compiled temporary file will be placed in builddir (this is better managed and can be deleted after compilation) |
-- Stagedir = <stagedir> |
Path for storing compiled library files. The default path is stage. |
-- Build-type = complete |
Compile all the versions. Otherwise, only a small part of the versions will be compiled, which is equivalent: Variant = release, threading = multi; link = shared | static; runtime-link = shared |
Variant = debug | release |
Determine the version to compile (debug or release ?) |
Link = static | shared |
Decide whether to use static or dynamic Databases |
Threading = single | multi |
Decide whether to use a single thread or multi-thread Library |
Runtime-link = static | shared |
Determines whether the database is static or dynamically linked to the C/C ++ standard library. |
-- With-<library> |
Compile only the specified database, for example, input -- With-RegEx to compile only the RegEx database. |
-- Show-libraries |
Display the name of the library to be compiled |
After the compilation is complete, install the header file and the generated library in the specified path (-- prefix ).
Note: the permissions of/usr/local/include/usr/local/lib/must be the highest. Otherwise, the library cannot be installed successfully.
Command:
Sudo chmod 777-r/usr/local/include/
Sudo chmod 777-r/usr/local/lib/
So far, if everything goes well, the installation is complete. Write a small program test, from the boost library full Development Guide-in-depth C ++ "quasi" standard library (revision) (by Luo Jianfeng, Electronic Industry Press 2012.5)
123456789101112131415 |
# Include <stdio. h> # Include <iostream> # Include <boost/Timer. HPP> Using namespace boost; Using namespace STD; Int main () { Timer T; Cout <"Max timespan:" <t. elapsed_max ()/3600 <"H" <Endl; Cout <"Min timespan:" <t. elapsed_min () <"S" <Endl; Cout <"now time elapsed:" <t. elapsed () <"S" <Endl; Return 1; } |
Program output:
max timespan: 0.596523h
min timespan: 1e-06s
n
***************************************************************************************
1. Download boost-1_52
Http://sourceforge.net/projects/boost/files/boost/1.54.0/boost_1_54_0.tar.gz/download
2. decompress the file in the/usr/local/directory.
3. Enter the/usr/local/boost-1_54_0/directory and enter
./Bootstrap. Sh
4. Enter the/usr/local/boost-1_54_0/directory and enter
Sudo./b2
5. Enter the/usr/local/boost-1_54_0/directory and enter
Sudo./Bjam-- Layout = versioned-- Build-type = complete-- Toolset = gccInstall
6. Add the environment variable (restart or unregister the environment variable to update it after modification)
Two methods:
(1) modify the/etc/profie file and add
Export boost_include =/usr/local/include/boost-1_54
Export boost_lib =/usr/local/lib
(2) create a new shell file boost. Sh in/etc/profile. d /.
#! /Bin/sh
Export boost_include =/usr/local/include/boost-1_54
Export boost_lib =/usr/local/lib
Test:
Test. cpp
[CPP] View plaincopy
- # Include <boost/lexical_cast.hpp>
- # Include <iostream>
- Int main ()
- {
- Using boost: lexical_cast;
- Int A = lexical_cast <int> ("123 ");
- Double B = lexical_cast <double> ("123.12 ");
- STD: cout <A <STD: Endl;
- STD: cout <B <STD: Endl;
- Return 0;
- }
Compile:
G ++ test. cpp-I $ boost_include-L $ boost_lib-O test./test
Output:
123
123.12
1. Download boost-1_52
Http://sourceforge.net/projects/boost/files/boost/1.54.0/boost_1_54_0.tar.gz/download
2. decompress the file in the/usr/local/directory.
3. Enter the/usr/local/boost-1_54_0/directory and enter
./Bootstrap. Sh
4. Enter the/usr/local/boost-1_54_0/directory and enter
Sudo./b2
5. Enter the/usr/local/boost-1_54_0/directory and enter
Sudo./Bjam-- Layout = versioned-- Build-type = complete-- Toolset = gccInstall
6. Add the environment variable (restart or unregister the environment variable to update it after modification)
Two methods:
(1) modify the/etc/profie file and add
Export boost_include =/usr/local/include/boost-1_54
Export boost_lib =/usr/local/lib
(2) create a new shell file boost. Sh in/etc/profile. d /.
#! /Bin/sh
Export boost_include =/usr/local/include/boost-1_54
Export boost_lib =/usr/local/lib
Test:
Test. cpp
[CPP] View plaincopy
- # Include <boost/lexical_cast.hpp>
- # Include <iostream>
- Int main ()
- {
- Using boost: lexical_cast;
- Int A = lexical_cast <int> ("123 ");
- Double B = lexical_cast <double> ("123.12 ");
- STD: cout <A <STD: Endl;
- STD: cout <B <STD: Endl;
- Return 0;
- }
Compile:
G ++ test. cpp-I $ boost_include-L $ boost_lib-O test./test
Output:
123
123.12