How to use Boost in Visual Studio 2010
有关如何在Visual Studio 2010中的空项目中使用Boost库的一步一步的解释是什么?
While Nate's answer is pretty good already, I'm going to expand on it more specifically for Visual Studio 2010 as requested, and include information on compiling in the various optional components which requires external libraries.
If you are using headers only libraries, then all you need to do is to unarchive the boost download and set up the environment variables. The instruction below set the environment variables for Visual Studio only, and not across the system as a whole. Note you only have to do it once.
C:boost_1_47_0
). Microsoft.Cpp.<Platform>.user
, and select Properties
to open the Property Page for edit. VC++ Directories
on the left. Include Directories
section to include the path to your boost source files. If you want to use the part of boost that require building, but none of the features that requires external dependencies, then building it is fairly simple.
C:boost_1_47_0
). bootstrap.bat
to build b2.exe (previously named bjam). Run b2:
b2 --toolset=msvc-10.0 --build-type=complete stage
; b2 --toolset=msvc-10.0 --build-type=complete architecture=x86 address-model=64 stage
Go for a walk / watch a movie or 2 / ....
Library Directories
section to include the path to your boost libraries output. (The default for the example and instructions above would be C:boost_1_47_0stagelib
. Rename and move the directory first if you want to have x86 & x64 side by side (such as to <BOOST_PATH>libx86
& <BOOST_PATH>libx64
). If you want the optional components, then you have more work to do. These are:
Boost.IOStreams Bzip2 filters:
C:bzip2-1.0.6
). -sBZIP2_SOURCE="C:bzip2-1.0.6"
when running b2 in step 5. Boost.IOStreams Zlib filters
C:zlib-1.2.5
). -sZLIB_SOURCE="C:zlib-1.2.5"
when running b2 in step 5. Boost.MPI
project-config.jam
in the directory <BOOST_PATH>
that resulted from running bootstrap. Add in a line that read using mpi ;
(note the space before the ';'). Boost.Python
To completely built the 32-bits version of the library requires 32-bits Python, and similarly for the 64-bits version. If you have multiple versions installed for such reason, you'll need to tell b2 where to find specific version and when to use which one. One way to do that would be to edit the file project-config.jam
in the directory <BOOST_PATH>
that resulted from running bootstrap. Add in the following two lines adjusting as appropriate for your Python installation paths & versions (note the space before the ';').
using python : 2.6 : C:PythonPython26python ;
using python : 2.6 : C:PythonPython26-x64python : : : <address-model>64 ;
Do note that such explicit Python specification currently cause MPI build to fail. So you'll need to do some separate building with and without specification to build everything if you're building MPI as well.
Follow the second set of instructions above to build boost.
Boost.Regex ICU support
C:icu4c-4_8
). <ICU_PATH>sourceallinone
. -sICU_PATH="C:icu4c-4_8"
when running b2 in step 5. While the instructions on the Boost web site are helpful, here is a condensed version that also builds x64 libraries.
Build the 32-bit libraries
This installs the Boost header files under C:Boostincludeboost-(version)
, and the 32-bit libraries under C:Boostlibi386
. Note that the default location for the libraries is C:Boostlib
but you'll want to put them under an i386
directory if you plan to build for multiple architectures.
bootstrap
Run: b2 toolset=msvc-12.0 --build-type=complete --libdir=C:Boostlibi386 install
toolset=msvc-11.0
toolset=msvc-10.0
toolset=msvc-14.1
Add C:Boostincludeboost-(version)
to your include path.
C:Boostlibi386
to your libs path. Build the 64-bit libraries
This installs the Boost header files under C:Boostincludeboost-(version)
, and the 64-bit libraries under C:Boostlibx64
. Note that the default location for the libraries is C:Boostlib
but you'll want to put them under an x64
directory if you plan to build for multiple architectures.
bootstrap
b2 toolset=msvc-12.0 --build-type=complete --libdir=C:Boostlibx64 architecture=x86 address-model=64 install
toolset=msvc-11.0
toolset=msvc-10.0
C:Boostincludeboost-(version)
to your include path. C:Boostlibx64
to your libs path. You can also try -j%NUMBER_OF_PROCESSORS% as an argument it will use all your cores. Makes things super fast on my quad core.
链接地址: http://www.djcxy.com/p/7682.html上一篇: Visual Studio 2010