Compile the boost library in Windows

Source: Internet
Author: User
Tags windows visual

 

The Boost library is a powerful, well-structured, cross-platform, open-source, and completely free C ++ library.

To use the Boost library, first check whether your development environment supports compiling the boost Library (http://www.boost.org/users/history/version_1_46_1.html)

Taking windows msvc compiler as an example, the supported boost libraries are Visual C ++: 7.1, 8.0, 9.0 10.0

If you are still using VC ++ 6.0, sorry. The VC6 compiler does not support many new features such as template-specific features, so some Boost libraries lack functions or even cannot be used.

How to install the Boost Library:

1. Download the compressed package from the Boost website (www.boost.org) and decompress it to any location on the local hard disk.

This article takes boost_000046_1 as an example. The decompression position is D: \ boost_000016_1 \

2. Go to the Directory D: \ boost_11216_1 \ and run the bootstrap.bat, bjam.exe program.

3. Command Line execution: bjam stage -- toolset = msvc-7.1 -- build-type = complete -- layout = versioned

Where,

Stage option specifies that boost is built locally. A stage directory will be created under the current directory, and the compiled lib library will be in it.

The toolset option specifies the compiler. For programmers who use visual studio development tools, you must correctly enter the msvc version:

Vs2003: msvc-7.1.

Vs2005 msvc-8.0

Vs2008: msvc-9.0

Vs2010 msvc-10.0

The build-type option specifies the compilation type,

The layout option specifies the library name to be compiled and the header file address directory name generation policy. Versioned is used in Windows by default.

 

Next, you can turn off the display screen to do other things, because the full compilation of the Boost library will take a lot of time (I spent about one hour on the pc ).

After the complete compilation, you need to set the include directory and library directory in visual studio IDE.

 

Windows Visual Studio 200x IDE general configuration

========================================================

Select:

1. Tools)

2. Options)

3. Project and Solutions (Project)

4. VC ++ Directories (VC ++ directory)

5. Show directories for (the directory that displays the following content): Add D: \ boost_000046_1 to Include Files

6. Show directories for (the directory that displays the following content): Add D: \ boost_000046_1 \ stage \ lib to Library Files

 

For Visual Studio 2010, configure the library directory and the inclusion directory from tools> options> project and solutions> VC ++ directories instead of your own project.

Add/import your own project first, In the properties manager of the project on the left side of the form

1. Click the first button (properties) to bring up the project properties page.

2. Select Configuration properties-> VC ++ directory

3. Add D: \ boost_000046_1 to the include directory.

4. Add D: \ boost_000046_1 \ stage \ lib to the library directory.

 

OK. Everything is ready. You can start using the Boost library. The following small program can test whether the boost library is correctly installed.

# Include <boost/thread. hpp>

# Include <iostream>

Void hello (){

Std: cout <"Hello world, I'm a thread! "<Std: endl;

}

Int main (int argc, char * argv []) {

Boost: thread thrd (& hello );

Thrd. join ();

Return 0;

}

If the installation is correct, a line of "Hello world, I'm a thread!" will be output on the console! .

 

 

It is time and effort-consuming to fully compile the Boost library, and it is not always used in development. You can also select the library to compile.

You only need to add the -- with-<Database Name> option in the Command running bjam, or -- without-<Database Name> to close compilation of a database.

Bjam also has many options. For more information, see bjam documentation.

 

This article is from the "maowang's blog ".

 

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.