Boost download and install the compilation configuration User Guide

Source: Internet
Author: User
Tags vc9

Theoretically, this article applies to various boost versions, especially the latest version 1.39.0. It applies to various C ++ compilers, such as vc6.0 (some libraries are not supported), vs2003, vs2005, vs2008, GCC, c ++ builder. First, we will summarize the Windows system.

1. Download

First download the latest boostinstallation package (1.39.0 is the latest version) from the official boost homepage ). Because some classes in boost need to be compiled into libraries for use, we also need to prepare a dedicated boost compilation auxiliary tool bjam. Many people on the internet advocate using the bjam source code included in the boost installation package directly to compile bjam. However, you need to modify several configuration scripts before compilation is successful. I personally think there is no need, and it is meaningless to pay for it. The boost official website provides the download link for the boost installation package and the bjam corresponding to the version of the installation package. the download is only over 200 kb and can be downloaded together.

Ii. Installation

Unzip the boost installation package to a local directory, such as: e:/SDK/boost_000039_and then copy bjam.exe to this directory (bjam must be in the same directory as the boost-build.jam ).

Iii. Compilation

Next is the most important compilation step. Open the command prompt (cmd.exe) window and run bjam. You can use the -- help parameter to view the Command help. The command line parameters of bjam are described in detail here, because it is very important. First, it involves the establishment of the programming environment. You need to select the appropriate command line parameters based on your specific use environment in the future. Second, it affects your hard disk space, if you have more than two ides at the same time (such as vc6 and vc9 coexist) and boost is required, you can calculate the number of hard disks used ...... Although today's hard drive space is not a problem, there should be a lot of people who advocate reasonable use of resources and are not used to extravagance and waste and advocate frugal. Based on the above two factors, the bjam command I use is as follows:

Bjam stage -- toolset = msvc-9.0 -- without-Python -- without-MPI -- without-wave -- without-graph -- without-math -- without-serialization -- stagedir = "E: /SDK/boost_000039_0/bin/vc9 "link = static runtime-link = shared threading = multi debug release

The following is a detailed explanation of the meaning of each parameter. Please read it carefully:

Stage/install: stage indicates that only the library (DLL and Lib) is generated. Install also generates the include directory containing the header file. I recommend using stage, because the include directory generated by install is actually the boost directory after the boost installation package is decompressed (E:/SDK/boost_1_39_0/boost, only a few non-HPP files are smaller than the include directory, so they can be used directly, and different ides can use the same pullover file, which saves Compilation Time, it also saves hard disk space.
Toolset: Specifies the compiler, such as Borland, GCC, msvc (vc6), and msvc-9.0 (vs2008.
Without/with: select which libraries are not compiled/compiled. I don't need any libraries such as Python and MPI, so I want to exclude them. In addition, static libraries such as wave, graph, math, RegEx, test, program_options, serialization, and signals are all very large, so they can be dropped without any need. This can be selected based on your needs. By default, all files are compiled. However, if you select to compile python, you must go to the official Python homepage download and install python.
Stagedir/Prefix: stagedir is used for stage, and prefix is used for install, which indicates the path of the compiled file. We recommend that you specify different directories for different ides. For example, vs2008 corresponds to E:/SDK/boost_000039_0/bin/vc9, and vc6 corresponds to E: /SDK/boost_000039_0/bin/vc6; otherwise, all files are generated under a directory, which is difficult to manage. If the install parameter is used, the header file directory will also be generated. vc9 corresponds to E:/SDK/boost_1_39_0/bin/vc9/include/boost-1_39/boost, vc6 is similar (the path here is cumbersome, and it is better to use stage ).
Build-Dir: the path of the intermediate file generated by compilation. This is useless here. It is in the root directory (E:/SDK/boost_000039_0) by default. The directory name is bin. v2. After compilation, you can delete all the directories (useless), so you do not need to set them.
Link: generate a dynamic or static Link Library. To generate a dynamic link library, you must use the shared method. To generate a static link library, you must use the static method. Generally, the boost library may be compiled in static mode, because the DLL with boost will be cumbersome for the final release program.
Runtime-link: Dynamic/static link C/C ++ Runtime Library. There are also two methods of shared and static, so that runtime-link and link can generate a total of four combination methods, each person can choose to compile according to their own needs. Generally, if Link is set to static only, you only need to compile two combinations: link = static runtime-link = shared and link = static runtime-link = static.
Threading: Single/multi-thread compilation. Generally, multiple threads are written. Of course, the Multi method must be specified. If you need to write a single thread program, you also need to compile a single thread library. You can use the single method.
Debug/release: Compile the debug/release version. It is usually the debug version of the library corresponding to the debug version of the program, so both are compiled.
After I have compiled the static link and dynamic link versions in the preceding methods, the entire E:/SDK/boost_000039_0 directory (including the library files decompressed by the installation package and compiled files) is less than 500 mb. In fact, after compilation, the decompressed files of the installation package can be deleted in addition to the boost Directory, which can free up MB of space. However, I have studied it again. In fact, the libs directory is also very useful. It provides examples for all boost classes and can be used as a reference; in addition, the doc directory is a complete boost help document. Of course, it is best not to delete it. In this way, the remaining directories and files add up to more than 10 MB, so leave a new path for them.
A complete and perfect boost directory was born.
If you don't want to know so much about it, you can use the following command to make it easy:
Bjam -- toolset = msvc-9.0 -- Build-type = complete
You can directly specify the compiler to compile in full mode, which can meet all future usage scenarios, but the consequence is:
1. Takes up more than 3 GB of hard disk space
2. Several hours of Compilation Time
3. the header file and library file are stored in C:/Boost (I am very disgusted)

4. Many generated files can never be used.

Iv. Configuration

Include Directory: e:/SDK/boost_000039_0
Library Directory: e:/SDK/boost_000039_0/bin/vc9
Add it to the corresponding path of the IDE.

V. Use

# Include <boost/thread. HPP>
In this case, the library file does not need to be included. The boost auto-Link Mechanism will automatically help us include the corresponding static Lib. That is to say, boost is linked in static mode by default, so our project property should also be set to multi-threaded (Debug ). If you want to use DLL Dynamic Link, you need to define the macro in advance:
# Define boost_all_dyn_link
Similarly, boost will include the corresponding lib by default. If you do not want to use the auto-Link Mechanism provided by boost, or do not feel at ease with its automatic link (in fact, you do not have to worry about it), you can define the macro in advance:
# Define boost_all_no_lib
Use the following link:
# Pragma comment (Lib, "boost_thread-vc90-mt-1_39.lib ")
# Pragma comment (Lib, "boost_thread-vc90-mt.lib ")
The two lib libraries are actually the same. I really don't understand why each library needs to be copied during boost compilation. Is it because the latter does not need to change the code after upgrading the boost version? There is also a useful macro:
# Define boost_lib_diagnostic
It allows VC to specify the boost Library and the link sequence in the output window during compilation.
For details about the auto-Link Mechanism of boost, you can refer to the Code in boost/config/auto_link.hpp, which is easy to understand and worth learning.

Vi. Differences between compiling and configuration in Linux:

My Linux and Windows use the shared directory to map the E:/SDK directory under windows into the/mnt/HGFS/SDK directory under Linux.
So the root directory of my boost source file is/mnt/HGFS/SDK/boost_000039_0 and CD.
Compile bjam:
CD tools/JAM
I finally got stuck when compiling bjam in Linux of the virtual machine. The screen shows mkdir, but the bajm has been compiled at this time.
Next, copy the bjam generated under the stage/bin. linuxx86 directory to boost_000039_0 in the root directory of the boost source file, and run CD to compile boost:
. /Bjam stage -- toolset = GCC -- with-date_time -- With-thread -- With-filesystem -- with-program_options -- stagedir = "/mnt/HGFS/SDK/boost_1_39_0/bin/GCC" link = static Runtime -Link = static threading = multi debug release
These parameters have the same meaning as those in windows, except that the compiler is changed to GCC, and other options are set as needed.
The generated library file is under the bin/GCC/lib directory, which is similar to that compiled by vc9. The lib directory feels redundant. manually copy the library file to the GCC directory, delete the Lib category, which is a matter of personal preferences.
Delete all the intermediate files, including the bin. V2 directory and tools/JAM/stage directory.
For the use of the boost library, in order not to write makefile every time, the boost header file and library file path are carried, and to make cross-platform programs share a set of code,
You can add the boost header file and library file path to the Linux environment variables. Open/etc/profile and add the following GCC environment variables:
Cplus_include_path = $ cplus_include_path: "/mnt/HGFS/SDK/boost_000039_0"
Export cplus_include_path

LIBRARY_PATH = $ LIBRARY_PATH: "/mnt/HGFS/SDK/boost_000039_0/bin/GCC"
In this way, you can directly use the boost header file and library file, and share a set of code with windows, which is very convenient.

7. Several popular articles on the Internet that can be referenced:

Installation of Boost: in vernacular C ++
Windows vc6 compiler install boost Library:
Boost compilation steps:
Boost 1.35.0 Visual Studio 2008 compiler guide:
Vs2008 install boost:

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