Install Boost_1_46_1 Library under win7+vs2010

Source: Internet
Author: User

First, the Boost library classification:

(1) Do not need to compile the library: Any, array, ASIO, conversion, CRC, BIND/MEM_FN, enable_if, function, lambda, MPL, smart_ptr ...

(2) Libraries that need to be compiled: Date_time, filesystem, function_types, graph, iostreams, math, MPI, Program_options, Python, regex, serialization, signals, System, test, thread, wave

Second, the full compilation boost will depend on some of the official libraries:

(1) Regex required Unicode support class library- ICU , compiling ICU is simpler, after you unlock the ICU package, you can find a directory called "ALLinONE" in its directory, with Visual Studio or Visual Studio Express open the inside of the Allinone.sln, choose release, that can be compiled, after compiling, the include directory and the Lib directory library files are copied out, respectively, placed in C:\icu\include and C:\icu\lib.

(2) The XML processing class library required by graph-Expat, download expat-win32bin-2.0.1 install to C:\expat.

(3) MPI required MPI Class Library--Boost's official site says it requires support such as Mpich or OPENMPI, and in fact always prompts for mpic++ under Windows, what you need is the Microsoft Cluster Pack SDK , downloaded and installed by default under the C:\ProgramFiles\Microsoft Compute Cluster pack. (Note: If the Microsoft HPC Pack SDK or Microsoft Compute Clusterpack is not installed under the default path, the Bjam will flying blind and the mpic++ path cannot be found. You can modify Mpi.jam at this time (in Boost_1_46_1\tools\build\v2\tools): local cluster_pack_path_native = "Your Path")

(4) Python required Python language library-python,download python 2.7.1 Windows Installer, install to C: \

Third, compile the boost library:

1. Download the installation package boost_1_46_1 Select Download Windows version

2. Unzip to the D:\boost directory

3. Running Bootstrap.bat

(1) from VS2010 's Tools menu, go to the Command Prompt window (click the Start button, point to All Programs, point to Microsoft Visual Studio 2010, point to Visual Studio Tools, and then click Visual Studio command Prompt (commands prompt) "
(2) CD-to-D:\boost\boost_1_46_1 execution Bootstrap.bat, then, will be generated under d:\boost\boost_1_46_1\ Bjam.exe

4. Set the compilation Environment (add red font)    
Modify the MSVC configuration of User-config.jam (D:\boost\boost_1_46_1\tools\build\v2\user-config.jam)

# MSVC Configuration
# Configure MSVC (default version, searched in standard location # and PATH).
# using MSVC;
Using msvc:10.0:: <compileflags>/wd4819 <compileflags>/d_crt_secure_no_deprecate
<compileflags>/d_scl_secure_no_deprecate <compileflags>/d_secure_scl=0;

To support MPI, you can add a line of "using MPI;" Can

5.cd to D:\boost\boost_1_46_1 execution
To compile the Boost library command:

Bjam install-s have_icu=1-s icu_path=c:\icu--toolset=msvc-10.0--build-type=complete link=static runtime-link=static --prefix= "E:\boost\boost_1_46_1" Threading=multi

Variant=release

(This step needs to wait a long time, about one hours or so ...) )

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. It is recommended to use stage, because the install generated by this include directory is actually the boost installation package extracted boost directory, so it can be used directly, and different Ides can use the same set of header files, which saves compilation time, but also save hard disk space.

Toolset: Specifies the compiler, optional such as Borland, GCC, msvc (VC6), msvc-10.0 (VS20010), and so on.

without/with: choose not to compile/compile which libraries, do not need to without off. 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 to download Python first.

stagedir/prefix:use prefix when using Stagedir,install at stage to indicate the path to the build file. (Note: When using the install, the include file directory structure is such a E:\boost\boost_1_46_1\include\boost_1_46_1\boost, the path is cumbersome, you can remove the middle layer of \boost_1_46_1. In any case, the individual feels the use of the stage good, on the one hand is fast, on the other hand is not so tangled directory)

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, the directory name is Bin.v2, and so on after the compilation can be completely deleted (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.

If you do not choose to install Python, two steps:

(1) bjam--without-python--toolset=msvc-10.0--build-type=complete

--prefix= "E:\boost\boost_1_46_1" Install

(2) bjam--with-python--toolset=msvc-10.0--build-type=complete

--prefix= "E:\boost\boost_1_46_1" Install

6. Setting the VS2010 Environment

(Note: In 2010 environment This step, in the project--right-click Properties-->vc++ directories to fill in the corresponding path)
Tools, Options, Projects and Solutions, VC + + Directories
Add E:\boost\boost_1_46_1\lib to the library files
Add E:\boost\boost_1_46_1\include to include files

Related:

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-vc100-mt-1_46.lib") or

#pragma comment (lib, "Boost_thread-vc100-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.

  

Another: 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 VC10 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_incl?_path= $CPLUS _incl?_path: "/mnt/hgfs/sdk/boost_1_45_0"

Export Cplus_incl?_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.

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.