Oli*_*ops 361 c++ boost visual-studio-2010
有关如何在Visual Studio中的空项目中使用Boost库的一步一步解释是什么?
KTC*_*KTC 506
虽然Nate的答案已经非常好了,但我将根据要求更具体地针对Visual Studio 2010进行扩展,并包含有关在需要外部库的各种可选组件中进行编译的信息.
如果您只使用标头库,那么您需要做的就是取消归档boost下载并设置环境变量.下面的说明仅为Visual Studio设置环境变量,而不是整个系统的环境变量.请注意,您只需要执行一次.
C:\boost_1_47_0
).Microsoft.Cpp.<Platform>.user
,然后选择Properties
打开属性页面进行编辑.VC++ Directories
左侧.Include Directories
部分以包含boost源文件的路径.如果你想使用需要构建的boost部分,但没有需要外部依赖的功能,那么构建它非常简单.
C:\boost_1_47_0
).bootstrap.bat
构建b2.exe(以前命名为bjam).运行b2:
b2 --toolset=msvc-10.0 --build-type=complete stage
; b2 --toolset=msvc-10.0 --build-type=complete architecture=x86 address-model=64 stage
去散步/看电影或2/....
Library Directories
部分以包含boost库输出的路径.(上面的例子和说明的默认值是C:\boost_1_47_0\stage\lib
.如果你想并排x86和x64(比如<BOOST_PATH>\lib\x86
&<BOOST_PATH>\lib\x64
),首先重命名并移动目录.如果您需要可选组件,那么您还有更多工作要做.这些是:
Boost.IOStreams Bzip2过滤器:
C:\bzip2-1.0.6
).-sBZIP2_SOURCE="C:\bzip2-1.0.6"
在步骤5中运行b2时添加选项.Boost.IOStreams Zlib过滤器
C:\zlib-1.2.5
).-sZLIB_SOURCE="C:\zlib-1.2.5"
在步骤5中运行b2时添加选项.Boost.MPI
project-config.jam
的目录<BOOST_PATH>
中的文件.添加一行读取using mpi ;
(注意';'之前的空格).Boost.Python的
要完全构建32位版本的库,需要32位Python,类似于64位版本.如果由于这个原因安装了多个版本,则需要告诉b2在哪里可以找到特定版本以及何时使用哪个版本.一种方法是编辑运行bootstrap导致project-config.jam
的目录<BOOST_PATH>
中的文件.添加以下两行,根据Python安装路径和版本进行调整(注意';'之前的空格).
using python : 2.6 : C:\\Python\\Python26\\python ;
using python : 2.6 : C:\\Python\\Python26-x64\\python : : : <address-model>64 ;
请注意,此类显式Python规范当前会导致MPI构建失败.因此,如果您正在构建MPI,那么您需要使用带有和不带规范的单独构建来构建所有内容.
按照上面的第二组说明构建boost.
Boost.Regex ICU支持
C:\icu4c-4_8
).<ICU_PATH>\source\allinone
.-sICU_PATH="C:\icu4c-4_8"
在步骤5中运行b2时添加选项.Nat*_*ate 155
虽然说明书上的升压网站是有帮助的,这里是一个浓缩版,也是建立64库.
这将安装Boost头文件C:\Boost\include\boost-(version)
和32位库C:\Boost\lib\i386
.请注意,库的默认位置是,C:\Boost\lib
但i386
如果您计划为多个体系结构构建,则需要将它们放在目录下.
bootstrap
跑: b2 toolset=msvc-12.0 --build-type=complete --libdir=C:\Boost\lib\i386 install
toolset=msvc-11.0
toolset=msvc-10.0
toolset=msvc-14.1
添加C:\Boost\include\boost-(version)
到您的包含路径.
C:\Boost\lib\i386
到libs路径.这将安装Boost头文件C:\Boost\include\boost-(version)
和64位库C:\Boost\lib\x64
.请注意,库的默认位置是,C:\Boost\lib
但x64
如果您计划为多个体系结构构建,则需要将它们放在目录下.
bootstrap
b2 toolset=msvc-12.0 --build-type=complete --libdir=C:\Boost\lib\x64 architecture=x86 address-model=64 install
toolset=msvc-11.0
toolset=msvc-10.0
C:\Boost\include\boost-(version)
到您的包含路径.C:\Boost\lib\x64
到libs路径.Aar*_*ack 20
您还可以尝试-j%NUMBER_OF_PROCESSORS%作为参数,它将使用您的所有核心.在我的四核上做得超级快.
Uri*_*Uri 14
我可以推荐以下技巧:创建一个特殊boost.props
文件
此过程具有仅在要显式包含它的项目中包含boost的值.如果您有一个使用boost的新项目,请执行以下操作:
编辑(从@ jim-fred编辑后):
生成的boost.props
文件看起来像这样......
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ImportGroup Label="PropertySheets" />
<PropertyGroup Label="UserMacros">
<BOOST_DIR>D:\boost_1_53_0\</BOOST_DIR>
</PropertyGroup>
<PropertyGroup>
<IncludePath>$(BOOST_DIR);$(IncludePath)</IncludePath>
<LibraryPath>$(BOOST_DIR)stage\lib\;$(LibraryPath)</LibraryPath>
</PropertyGroup>
</Project>
Run Code Online (Sandbox Code Playgroud)
它包含用于提升目录位置的用户宏(在本例中为D:\ boost_1_53_0)和另外两个参数:IncludePath和LibraryPath.语句#include <boost/thread.hpp>
会在相应的目录中找到thread.hpp(在本例中为D:\ boost_1_53_0\boost\thread.hpp).'stage\lib \'目录可能会根据安装目录而改变.
此boost.props文件可以位于D:\boost_1_53_0\
目录中.
fre*_*low 13
您需要Boost的哪些部分?很多东西都是Visual Studio附带的TR1的一部分,所以你可以简单地说,例如:
#include <tr1/memory>
using std::tr1::shared_ptr;
Run Code Online (Sandbox Code Playgroud)
根据James的说法,这也应该有效(在C++ 0x中):
#include <memory>
using std::shared_ptr;
Run Code Online (Sandbox Code Playgroud)
这个帖子已经有一段时间了,我想我会在你的特定硬件上添加一些关于尽可能快地构建Boost的东西.
如果你有4或6核分别使用-j5或-j7.当然不是标准版本,也不是-j2,除非你确实有双核心.
我正在运行一个Sandy Bridge Extreme,我的主站上有3930K(6核),但旧备份盒上有2600k(4核),趋势是我用N +获得最好的Boost编译时间1构建过程,其中N是物理核心的数量.N + 2达到收益递减点,时间也会增加.
备注:启用超线程,32GB RAM DDR3,三星840 EVO SSD.
-j7 on 6-core(2分51秒)(Win7 Ultimate x64)(Visual Studio 2013)
PS C:\Boost\boost_1_56_0> measure-command { .\b2 -j7 --build-type=complete msvc stage }
Days : 0
Hours : 0
Minutes : 2
Seconds : 51
Milliseconds : 128
Ticks : 1711281830
TotalDays : 0.0019806502662037
TotalHours : 0.0475356063888889
TotalMinutes : 2.85213638333333
TotalSeconds : 171.128183
TotalMilliseconds : 171128.183
Run Code Online (Sandbox Code Playgroud)
-j6 on 6-core(3分2秒)(Win7 Ultimate x64)(Visual Studio 2013)
PS C:\Boost\boost_1_56_0> measure-command { .\b2 -j6 --build-type=complete msvc stage }
Days : 0
Hours : 0
Minutes : 3
Seconds : 2
Milliseconds : 809
Ticks : 1828093904
TotalDays : 0.00211584942592593
TotalHours : 0.0507803862222222
TotalMinutes : 3.04682317333333
TotalSeconds : 182.8093904
TotalMilliseconds : 182809.3904
Run Code Online (Sandbox Code Playgroud)
-j8 on 6-core(3分17秒)(Win7 Ultimate x64)(Visual Studio 2013)
PS C:\Boost\boost_1_56_0> measure-command { .\b2 -j8 --build-type=complete msvc stage }
Days : 0
Hours : 0
Minutes : 3
Seconds : 17
Milliseconds : 652
Ticks : 1976523915
TotalDays : 0.00228764342013889
TotalHours : 0.0549034420833333
TotalMinutes : 3.294206525
TotalSeconds : 197.6523915
TotalMilliseconds : 197652.3915
Run Code Online (Sandbox Code Playgroud)
配置
Building the Boost C++ Libraries.
Performing configuration checks
- 32-bit : yes (cached)
- arm : no (cached)
- mips1 : no (cached)
- power : no (cached)
- sparc : no (cached)
- x86 : yes (cached)
- has_icu builds : no (cached)
warning: Graph library does not contain MPI-based parallel components.
note: to enable them, add "using mpi ;" to your user-config.jam
- zlib : no (cached)
- iconv (libc) : no (cached)
- iconv (separate) : no (cached)
- icu : no (cached)
- icu (lib64) : no (cached)
- message-compiler : yes (cached)
- compiler-supports-ssse3 : yes (cached)
- compiler-supports-avx2 : yes (cached)
- gcc visibility : no (cached)
- long double support : yes (cached)
warning: skipping optional Message Passing Interface (MPI) library.
note: to enable MPI support, add "using mpi ;" to user-config.jam.
note: to suppress this message, pass "--without-mpi" to bjam.
note: otherwise, you can safely ignore this message.
- zlib : no (cached)
Run Code Online (Sandbox Code Playgroud)
我注意到64位构建需要更长的时间,我需要对它们进行相同的比较并进行更新.
以下是我如何使用 Boost:
您将能够在没有任何错误的情况下构建您的项目!
从以下网址下载增强功能:http : //www.boost.org/users/download/, 例如svn
之后:cmd->转到boost目录(“ D:\ boostTrunk”-您在其中签出或下载并解压缩包):command: bootstrap
我们在(“ D:\ boostTrunk”)中创建了bjam.exe,之后:命令: bjam toolset = msvc-10.0 variant = debug,释放线程= multi link = static (这需要一些时间〜20min。)
之后:打开Visual Studio 2010->创建空项目->转到项目属性->设置:
粘贴此代码,然后检查其是否有效?
#include <iostream>
#include <boost/shared_ptr.hpp>
#include <boost/regex.hpp>
using namespace std;
struct Hello
{
Hello(){
cout << "Hello constructor" << endl;
}
~Hello(){
cout << "Hello destructor" << endl;
cin.get();
}
};
int main(int argc, char**argv)
{
//Boost regex, compiled library
boost::regex regex("^(Hello|Bye) Boost$");
boost::cmatch helloMatches;
boost::regex_search("Hello Boost", helloMatches, regex);
cout << "The word between () is: " << helloMatches[1] << endl;
//Boost shared pointer, header only library
boost::shared_ptr<Hello> sharedHello(new Hello);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
资源:https : //www.youtube.com/watch?v=5AmwIwedTCM