Boost download Install compile Configuration Usage Guide (including Windows and Linux

Source: Internet
Author: User
Tags vc9

Theoretically, this article applies to each version of Boost, especially the latest version of 1.45.0, and applies to a variety of C + + compilers, such as VC6.0 (not supported in some libraries), vs2003,vs2005,vs2008,gcc,c++ Builder, and so on. Let's summarize the Windows system.
First, download
First from the Boost official homepageattached linkDownload the latest version of the Boost installation package (currently the latest version is boost_1_45_0.7z).
Second, installation
Unzip the boost installation package to a local directory, such as E:\SDK\boost_1_45_0. Because the boost is a classification that needs to be compiled into a library, we also need to prepare the boost dedicated compilation helper Bjam. At the command prompt (Cmd.exe), execute the Bootstrap.bat in the root directory, and the compiled Bjam.exe is automatically copied to the directory (Bjam must be in the same sibling directory as Boost-build.jam).
Third, compile
The next step is the most important compilation steps. To open a command prompt (Cmd.exe) window and execute Bjam, you can use the--help parameter to view command Help. Here is a detailed explanation of Bjam's command-line parameters, because it is very important. First of all, it involves the construction of the programming environment, you need to choose the appropriate command line parameters according to your own future use environment, second, it affects your hard disk space, fully compiled word is said to be above 3G, if you have more than 2 IDE (such as VC6 and VC9 coexistence) and all need to use boost, So how many hard drives you can count on yourself ... Although now everyone's hard disk space is not a problem, but like I advocate the rational use of resources not accustomed to extravagance and frugality to promote the lad should be a few. Combined with the above two factors, I use the Bjam command as follows:
Bjam stage--toolset=msvc-9.0--without-graph--without-graph_parallel--without-math--without-mpi--without-python- -without-serialization--without-wave--stagedir= "E:\SDK\boost_1_45_0\bin\vc9" Link=static runtime-link=shared Threading=multi Debug Release

Here's a detailed explanation of what each parameter means, so be sure to read it carefully:
Stage/install:stage means that only libraries (DLLs and Lib) are generated, and install also generates an include directory with header files. I recommend using the stage, because the install generated by this include directory is actually the boost installation package extracted boost directory (E:\SDK\boost_1_45_0\boost, only a few more non-HPP files than the Include directory, are small), so they can be used directly, and different Ides can use the same set of header files, saving both compilation time and hard disk space.
Toolset: Specifies the compiler, optional such as Borland, GCC, msvc (VC6), msvc-9.0 (VS2008), and so on.
Without/with: Choose which libraries are not compiled/compiled. Because Python, MPI and other libraries I do not need, so ruled out. In addition, wave, graph, math, regex, Test, program_options, serialization, signals these libraries made up of the static Lib are very large, so do not need to also can without out. This can be selected according to individual needs, by default it is all compiled. However, it is important to note that if you choose to compile Python, you need the Python language support and should go to the official Python homepageattached linkDownload the installation.
Stagedir/prefix:stage when using Stagedir,install, prefix is used to indicate the path of the compiled makefile. It is recommended to specify different directories for different Ides, such as VS2008 corresponding to the E:\SDK\BOOST_1_45_0\BIN\VC9,VC6 corresponding to the E:\SDK\BOOST_1_45_0\BIN\VC6, otherwise all generated under a directory, difficult to manage. If you use the install parameter, you will also generate a header file directory, vc9 corresponding to the E:\SDK\BOOST_1_45_0\BIN\VC9\INCLUDE\BOOST-1_45\BOOST,VC6 similar (light this path is so cumbersome, Or use the stage well).
Build-dir: The path to the intermediate file generated by the compilation. This I do not work here, the default is in the root directory (E:\SDK\BOOST_1_45_0), the directory name is Bin.v2, and so on after the compilation is complete can delete this directory (useless), so do not need to set.
Link: Generate a dynamic link library/static link library. Building a dynamic-link library requires the use of shared methods, and static-link libraries need to be built using static methods. The general boost library may be compiled in a static fashion, because the final release program feels a bit cumbersome with boost DLLs.
Runtime-link: Dynamic/static link C/C + + Runtime library. There are also shared and static two ways, so that runtime-link and link can produce a total of 4 combinations, each can choose to build according to their own needs. General link only choose static words, only need to compile 2 kinds of combinations can, namely Link=static runtime-link=shared and Link=static runtime-link=static.
Threading: Single/Multithreaded compilation. Generally write multi-threaded programs, of course, to specify the multi way, if you need to write a single-threaded program, you also need to compile a single libraries, you can use the simple.
Debug/release: Compile the debug/release version. Generally, the debug version of the program corresponds to the debug version of the library, so two are compiled.
After I compiled the static link and the dynamic link two versions according to the above method, the whole E:\SDK\boost_1_45_0 directory (including the installation package unzip the file and compile the generated library file) is less than 500MB. In fact, after the completion of the compilation of the package extract files in addition to the boost directory and other directories and files can be deleted, so you can also free up 150MB of space. But I studied again, in fact Libs This directory is also very useful, it provides all the use of the boost class, usually as a reference, and the doc directory is a complete boost using the Help document, of course, it is best not to delete. So the remaining directories and files add up to more than 10 trillion, simply give them a way to live it.
Hehe, a complete and perfect boost catalog was born.
If you don't want to know so much about the diagram, there are simple ways to use the command:
Bjam--toolset=msvc-9.0--build-type=complete
Directly specify that the compiler is compiled in full mode, which will satisfy all future uses, but at the same time result:
1, occupy more than 3G of hard disk space
2, take up a few hours of compilation time
3, head files and library files stored in C:\Boost (personal very disgusted)

4, many of the generated files can never be used
Iv. Configuration
Include directory: E:\SDK\boost_1_45_0
Library Catalog: E:\SDK\BOOST_1_45_0\BIN\VC9
Add to the IDE's corresponding path.
V. Use of
Examples of Use:
#include <boost\thread.hpp>
In this case, without a library file, the boost Auto-link mechanism will automatically help us to include the corresponding static lib. In other words, boost is statically linked by default, so our engineering properties are best set to multi-threaded (Debug). If you want to use DLL dynamic chaining, you need to pre-define macros:
#define Boost_all_dyn_link
Similarly, boost will also default to include the corresponding Lib for us at this time. If you do not want to use the Auto-link mechanism provided by boost, or if you are not comfortable with its automatic links (in fact, you can not worry about it), you can pre-define macros:
#define Boost_all_no_lib
Then use the following methods to link:
#pragma comment (lib, "Boost_thread-vc90-mt-1_45.lib")
Or
#pragma comment (lib, "Boost_thread-vc90-mt.lib")
The two Lib is actually the same, I really do not understand why the boost compile every library to copy one, is it because the latter after upgrading the boost version without changing the code? There's also a more useful macro:
#define Boost_lib_diagnostic
It allows the VC in the Output window at compile time to specify which boost libraries and link sequences are specifically linked by the program.
About the auto-link mechanism of boost, in detail can see the code in BOOST\CONFIG\AUTO_LINK.HPP, it is easy to read, and it is worth learning.
Six, Linux under the difference between the compilation and configuration:
My Linux and Windows use a shared directory that maps the E:\SDK directory under Windows to the/MNT/HGFS/SDK directory under Linux.
So my boost source file root directory is/MNT/HGFS/SDK/BOOST_1_45_0,CD in.
First you need to compile Bjam:

CD Tools/jam
./build_dist.sh

I am in the virtual machine under the Linux compiler Bjam the end will be stuck, the screen shows to the mkdir place will not go down, but in fact this time BAJM has been compiled to complete.
Next, copy the generated bjam from the Stage/bin.linuxx86 directory to the Boost source file root directory boost_1_45_0, CD in, and start compiling boost:

./bjam stage--TOOLSET=GCC--with-date_time--with-thread--with-filesystem--with-program_options--stagedir= "/mnt/ HGFS/SDK/BOOST_1_45_0/BIN/GCC "link=static runtime-link=static threading=multi Debug Release

The meaning of these parameters is exactly the same as under Windows, except that the compiler changes to GCC, and the other options are set according to your needs.
The generated library file is in the Bin/gcc/lib directory, the same as the Vc9 compiled, the Lib directory feels redundant, manually copy the library files to the GCC directory, delete the Lib directory, this is a matter of personal preference.
Then delete all the intermediate files, including the Bin.v2 directory and the Tools/jam/stage directory.
About the use of the boost library, in order to not write makefile each time the Boost header file and library file path with, and in order to let cross-platform program common set of code,
You can add boost header files and library file paths to Linux environment variables. Open/etc/profile and add the following GCC environment variables:

Cplus_include_path= $CPLUS _include_path: "/mnt/hgfs/sdk/boost_1_45_0"
Export Cplus_include_path

Library_path= $LIBRARY _path: "/MNT/HGFS/SDK/BOOST_1_45_0/BIN/GCC"
Export Library_path

This allows you to use the Boost header and library files directly, and it is convenient to share a set of code with Windows.
Seven, can refer to the online popular articles:
Vernacular C + + installation boost: attached link
Windows VC6 compile and install the Boost library: attached link
Boost compilation step: Attach link
Boost 1.35.0 Visual Studio 2008 Compilation Guide: attached link
VS2008 under Installation boost:http://www.cnblogs.com/xdotnet/archive/2008/03/22/boost_install_config.html

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.