Because of the cross-platform, now to use the boost library, the boost library is very large, is now in the exploratory phase.
First of all, the boost library is installed and used under window.
First, download
Start by downloading the latest boost installation package from the Boost official homepage http://www.boost.org/, or use subversion to get the latest version with the address: Http://svn.boost.org/svn/boost/trunk. I now generally use SVN, which makes it easy to update and build, instead of downloading new installation packages and rebuild each time.
Second, installation
If you are using a downloaded installation package, extract the Boost installation package to a local directory, such as: E:\SDK\boost, or use the Boost code checkout to this directory if you are using SVN. 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----I'm using VS2008.
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 rational use of resources not accustomed to waste to promote thrift of children's shoes should be people, so do not need the configuration and the library can not be compiled. 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\bin\vc9" link=static runtime-link=shared runtime-link=static threading=multi Debug Release
The meanings of each parameter are explained in detail below:
Stage/install:Stage indicates that only libraries (DLLs and Lib) are generated, and install also generates an include directory containing header files. I recommend using stage, because the install generated by this include directory is actually the boost installation package extracted boost directory (E:\SDK\boost\boost, only a few more non-HPP files than the Include directory, are very small), So you can use it directly, and different Ides can use the same set of header files, which saves 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. There are waves, 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 the needs of each individual, by default, all compilation. However, it is important to note that if you choose to compile Python, you need the Python language support and should download the installation to the official Python homepage http://www.python.org/. The command to view the boost include library is
Bjam--show-libraries。
Stagedir/prefix:When using Stagedir,install at stage, prefix is used to represent the path to the build file. It is recommended to specify different directories for different Ides, such as VS2008 corresponding to the E:\SDK\BOOST\BIN\VC9,VC6 corresponding to the E:\SDK\BOOST\BIN\VC6, otherwise all generated under a directory, difficult to manage. If the install parameter is used, the header file directory will also be generated, vc9 corresponding to the E:\SDK\BOOST\BIN\VC9\INCLUDE\BOOST-1_46\BOOST,VC6 similar (light this path is so cumbersome, or use the stage good).
Build-dir:Compiles the path of the resulting intermediate file. This I do not work here, the default is in the root directory (E:\SDK\boost), 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 linking of C + + run-time libraries. 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, I generally make up these two kinds of combination.
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. I compiled the static link and dynamic link according to the above two versions, the entire E:\SDK\boost directory has 1.28G. If you do not plan to upgrade the boost version in the future, You can then delete the compiled intermediate file bin.v2 directory, so that the entire directory (including the installation package decompression files and compiled generated library files) will be reduced to less than 800MB, if Runtime-link only choose one way, then the entire directory is only 600MB. In fact, after the completion of the compilation, in addition to the boost and bin directory and other directories and files can be deleted, so you can also free up 350MB 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. Several other directories and files add up to a few 10 trillion, simply give them a way to live. Hehe, a complete and perfect boost catalog was born.
It is important to note that if you compile boost with VS2008 (other versions of VCs are not tested, there may be similar problems), then if you call Boost, the main program adds _bind_to_current_vclibs_ Version predefined macros to force the use of the latest version of the Windows CRT library, then your boost will also need to add this predefined macro to compile, otherwise it will cause the program because the version of the CRT libraries used by the non-uniform "run on some machines" because the application configuration is incorrect, Application failed to start ' problem ', please refer to my other article on this issue: "Original" resolves a VS2008 compiled program running on some machines prompting the "application failed to start due to application configuration is not correct" issue. To add this predefined macro, open the BOOST\CONFIG\COMPILER\VISUALC.HPP at the top of the boost installation root:
Added by Terry, 2011/4/19, force the linker to use the latest version of Crt/mfc/atl DLL
#ifndef _bind_to_current_vclibs_version
#define _bind_to_current_vclibs_version 1
#endif//_bind_to_current_vclibs_version
This method modified the boost source, not what I wanted, but helpless did not find a better way, if someone knows that want to leave a message to tell me.
If the diagram is convenient, do not want to know so much, then there is a simple way, you can use the command: Bjam--toolset=msvc-9.0--build-type=complete directly specify the compiler in full-mode compilation, so that it can meet all future use of the situation, But at the same time, the result is: 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 (I very disgusted)
4, many of the generated files can never be used
Iv. Configuration
Include directory: E:\SDK\boostlibrary directory: E:\SDK\boost\bin\vc9\lib
Add to the IDE's corresponding path.
V. Use of
Use example: #include <boost\thread.hpp> at this time, without the 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 again, BOOST will also default to help us include the corresponding lib. If you don't want to use the Auto-link mechanism provided by BOOST, or if you're not comfortable with its automatic links (you don't have to worry about it), you can pre-define macros: #define BOOST_ALL_NO_LIB and then use the following methods to link: #pragma comment ( LIB, "Boost_thread-vc90-mt-1_47.lib") or #pragma comment (lib, "Boost_thread-vc90-mt.lib") These two lib are actually the same, I really do not understand why the boost compilation when every library to copy one, is it because the latter after upgrading the boost version without changing the code? There is 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.
Build and use of the Boost library under Windows