Install boost under Windows compilation

Source: Internet
Author: User
Tags vc9

The compilation and use of boost, after collecting data and summarizing, is documented. Thank you to the author of the references listed below.

1 Downloads

Address: http://sourceforge.net/projects/boost/files/boost/1.56.0/

You can choose boost_1_56_0.7z Download.

2 Compiling 2.1 Generate boost for your own build tool Bjam.exe

after decompression, compile with VS2013. First Open "VS2013 developer Command Prompt", CD to boost after decompression root directory:E:\XXX\boost_1_56_0, execute bootstrap.bat. Generates B2.exe, Bjam.exe, Project-config.jam, bootstrap.log four files in the boost root directory.

Among them, B2.exe, bjam.exe the two EXE function is the same, Bjam.exe is the old version, B2 is the upgrade version of Bjam.

2.2 using Bjam (or B2) to compile boost

1. Bjam Command parameter Analysis

We use the article "1" in the command to analyze the role of each parameter (the original author extracted the boost root directory is E:\SDK\boost).

Debug Release

(1) 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.

(2) Toolset:

Specifies the compiler, optional such as Borland, GCC, msvc (VC6), msvc-9.0 (VS2008), and so on.

(3) 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.

(4) Stagedir/prefix:

When using Stagedir,install at stage, prefix is usedto 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).

(5) 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.

(6) 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.

(7) 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.

(8) 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.

(9) 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.

2. Compile boost

The command to compile boost is more complicated, especially link, runtime-link the function of these two options is not clear, they have 4 kinds of mutual combination, which each have what meaning?

So first do an experiment, just compile the Date_time library and see what these two options do.

Use the following command-line compilation, respectively,

B2 stage--toolset=msvc-12.0--with-date_time--stagedir= "E:\ECODE\BOOST_1_56_0\BIN\VC12"link=static runtime-link=staticThreading=multiDebugreleaseb2 Stage--toolset=msvc-12.0--with-date_time--stagedir= "E:\ECODE\BOOST_1_56_0\BIN\VC12"link=static runtime-link=sharedThreading=multiDebugreleaseb2 Stage--toolset=msvc-12.0--with-date_time--stagedir= "E:\ECODE\BOOST_1_56_0\BIN\VC12"link=shared runtime-link=sharedThreading=multiDebugreleaseb2 Stage--toolset=msvc-12.0--with-date_time--stagedir= "E:\ECODE\BOOST_1_56_0\BIN\VC12"link=shared runtime-link=staticThreading=multiDebugreleaseb2 Stage--toolset=msvc-12.0--with-date_time--stagedir= "E:\eCode\boost_1_56_0\bin\vc12_2" (to avoid overwriting previous results, configure another directory Vc12_2 storage)
B2 stage--toolset=msvc-12.0--with-date_time--stagedir= "E:\eCode\boost_1_56_0\bin\vc12_2"--build-type=complete(to avoid overwriting previous results, configure another directory Vc12_3 storage)

The resulting results are shown in the following table:

Serial number Link Runtime-link Generated objects Note
1 Static Static

Libboost_date_time-vc120-mt-sgd-1_56.lib

Libboost_date_time-vc120-mt-s-1_56.lib

2 Static Shared

Libboost_date_time-vc120-mt-gd-1_56.lib

Libboost_date_time-vc120-mt-1_56.lib

Same as 5 results
3 Shared Shared

Boost_date_time-vc120-mt-gd-1_56.dll

Boost_date_time-vc120-mt-gd-1_56.lib

Boost_date_time-vc120-mt-1_56.dll

Boost_date_time-vc120-mt-1_56.lib

4 Shared Static Error, unable to compile
5 Use the default Use the default

Libboost_date_time-vc120-mt-gd-1_56.lib

Libboost_date_time-vc120-mt-1_56.lib

Same as 2 results

And when debug release is omitted, the debug release version is compiled

6 use--build-type=complete

Boost_date_time-vc120-mt-gd-1_56.dll

Boost_date_time-vc120-mt-gd-1_56.lib

Boost_date_time-vc120-mt-1_56.dll

Boost_date_time-vc120-mt-1_ 56.lib

 

Libboost_date_time-vc120-mt-sgd-1_56.lib

libboost_date_time-vc120-mt-s-1_56. Lib

 

Libboost_date_time-vc120-mt-gd-1_56.lib

Libboost_date_time-vc120-mt-1_56.lib

 

Libboost_date_time-vc120-s-1_56.lib

Libboost_date_time-vc120-sgd-1_56.lib

--build-type=complete, you can see the link,runtime-link of the

3 combination of debug, release of the multi-threaded version is generated,

In addition, also generated a link =static,runtime-link=static Debug, Release's single-threaded version

As you can see from the above results, the default configuration for link and Runtime-link is link=static runtime-link=shared, so we can use (B2 stage--toolset=msvc-12.0 --with-date_time --stagedir= "E:\eCode\boost_1_56_0\bin\vc12_2") command line to compile boost.

In addition, we can analyze the naming features of the Boost library: "2"

(1) "Lib" begins with the "link=static" version (static link library version, no DLL), and "boost" is the "link=shared" version (dynamic link library version, including Lib and DLL).

(2) All libraries contain a "boost" prefix.

(3) The Boost library name (e.g. Date_time library) is immediately followed.

(4) Then the version of the compiler, separated from the library name with "-" instead of an underscore "_" (such as-vc120).

(5) There is "Mt" for the "Threading=multi" version, there is no "threading=single" version.

(6) "s" for "runtime-link=static" version, no "runtime-link=shared" version.

(7) There is "GD" for the debug version, no is the release version.

(8) All libraries contain the end of the version number of the Boost library (for example, 1_56, where the "." The underscore "_" instead)

3. Link, runtime-link portfolio analysis

The article "2" gives the concrete function analysis of link,runtime-link.

Assuming that a library a relies on library B, our own program client relies on library A, which is:

So, link means client->a,runtime-link refers to a-B

Configuration

Link process

Files required at run time

Link=static

Runtime-link=static

The client statically contains a through A.A (A.lib);

A by B.A (B.lib) statically contains B;

It's not about. So. dll

Client

Link=static

Runtime-link=shared

The client statically contains a through A.A (A.lib);

At run time, the client dynamically calls B.so (B.dll)

Client

B.so (B.dll)

Link=shared

Runtime-link=shared

The client will contain A.A (A.lib);

A will contain B.A (B.lib);

But all only save the real implementation of the dynamic library stub, the runtime through the stub to dynamically load A.so (A.dll), b.so (B.dll) implementation

Client

A.so (A.dll)

B.so (B.dll)

Link=shared

Runtime-link=static

The client will contain A.A (A.lib), but only the actual stub is implemented;

A by B.A (B.lib) statically contains B;

At runtime, the client dynamically calls A.so (A.dll)

Client

A.so (A.dll)

3. Configuration

Include path with header file: E:\eCode\boost_1_56_0

Link path containing the library file: E:\eCode\boost_1_56_0\bin\vc12\lib

(1) can be set to current project only:

Check current project->properties->configuration properties->c/c++->general:additional Include Directories: Set E : \ecode\boost_1_56_0

Check current project->properties->configuration properties->linker->general:additional LibraryDirectories: Set E : \ecode\boost_1_56_0\bin\vc12\lib

(2) can be set to the current solution only:

Select the current project->properties->configuration properties->vc++ directories:

Include Directories: Setting E:\ECODE\BOOST_1_56_0

Librarydirectories: Set E:\eCode\boost_1_56_0\bin\vc12\lib

(3) can be set to the OS current user under the VC + + environment (the current user under VC + + created by all solution)

Under an open project, switch to the Property Manager tab, then expand the properties configuration for the current project, and open the Microsoft.Cpp.Win32.User

Select Common properties->vc++ Directories:

Include Directories: Setting E:\ECODE\BOOST_1_56_0

Librarydirectories: Set E:\eCode\boost_1_56_0\bin\vc12\lib

This setting only works under the WIN32 compilation option, and the x64 compilation option requires an additional configuration of the x64 Properties sheet.

(4) can be set to the OS all users under the VC + + Environment

You can edit Microsoft.Cpp.Default.props, Microsoft.Cpp.props. There is no introduction here.

4. Testing

Use the Date_time timer function in the article "3". Create a WIN32 console project, and then copy the following code

//#define Boost_date_time_source#include <iostream>#include<boost/date_time/gregorian/gregorian.hpp>#include<boost/date_time/posix_time/posix_time.hpp>using namespacestd;using namespaceBoost::gregorian;using namespaceboost::p osix_time;/************************************************************************Create a microsecond-level timer************************************************************************/Template<classT = microsec_clock>classmytimer{Private: Ptime m_starttime; Public: MyTimer () {Restart (); }    voidRestart () {m_starttime=T::local_time (); }    voidElapsed () {cout<< t::local_time ()-M_starttime <<Endl; }};intMain () {MyTimer<microsec_clock>T;  for(inti =0; I < -; ++i) {cout<<"Hello"<<Endl; } t.elapsed ();}

Notice that the macro "#define Boost_date_time_source" at the beginning was dropped. If you enable this macro definition, the embedded header files are recompiled by default, and if you do not enable this macro definition, the Date_time libraries that are compiled by the system are used.

(1) Disable the # define Boost_date_time_source macro and then Libboost_date_time-vc120-mt-gd-1_56.lib from E:\eCode\boost_1_56_0\bin\vc12\ LIB, when compiling the debug version of the program, prompted the connection error, missing libboost_date_time-vc120-mt-gd-1_56.lib.

(2) Enable # define Boost_date_time_source macros, compile the debug version of the program, you can find even in the absence of libboost_date_time-vc120-mt-gd-1_56.lib, can also be compiled successfully.

References

"1" Boost download Install compile Configuration Usage guide (including Windows, Linux, and Arm Linux) (http://www.cnblogs.com/wondering/archive/2009/05/21/boost_setup.html)

"2" link and runtime-link, with shared and static (http://blog.csdn.net/yasi_xi/article/details/8660549)

"3" Chronograph function (ii) (http://www.cnblogs.com/jerry19880126/archive/2013/02/20/2919718.html)

"4" Official document getting Started on Windows (http://www.boost.org/doc/libs/1_56_0/more/getting_started/windows.html)

"5" Bjam use (http://blog.chinaunix.net/uid-22301538-id-3158997.html)

Install boost under Windows compilation

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.