关于如何在Visual Studio的空项目中使用Boost库的一步一步的解释是什么?
当前回答
一个简单的例子,让你开始在Visual Studio:
1.从这里下载并解压Boost。
2.创建一个Visual Studio空项目,使用一个不需要单独编译的示例boost库:
#include <iostream>
#include <boost/format.hpp>
using namespace std;
using namespace boost;
int main()
{
unsigned int arr[5] = { 0x05, 0x04, 0xAA, 0x0F, 0x0D };
cout << format("%02X-%02X-%02X-%02X-%02X")
% arr[0]
% arr[1]
% arr[2]
% arr[3]
% arr[4]
<< endl;
}
3.在Visual Studio项目属性中设置附加包含目录:
举个简单的例子:
如何在Visual Studio中安装Boost库
如果你不想使用整个boost库,只使用一个子集:
使用Windows中的boost库的子集
如果你现在特别想了解需要编译的库:
如何在Windows中使用Boost编译库
其他回答
我可以推荐以下技巧:创造一种特殊的刺激。道具文件
打开物业管理 右键单击项目节点,选择“添加新项目属性表”。 选择一个位置并命名您的属性表(例如:c:\mystuff\boost.props) 将附加的Include和Lib文件夹修改为搜索路径。
此过程的价值是仅在希望显式包含boost的项目中包含它。当你有一个使用boost的新项目时,请:
打开物业管理器。 右键单击项目节点,并选择“添加现有属性表”。 选择boost属性表。
编辑(以下编辑来自@jim-fred):
由此产生的推动力。道具文件看起来像这样…
<?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>
它包含一个用于boost目录位置的用户宏(在本例中为D:\boost_1_53_0)和另外两个参数:IncludePath和LibraryPath。语句#include <boost/thread.hpp>将在适当的目录中找到thread.hpp(在本例中为D:\boost_1_53_0\boost\thread.hpp)。'stage\lib\'目录可能会根据安装到的目录而改变。
这提振。props文件可以位于D:\boost_1_53_0\目录中。
还有一个小提示:如果你想减少编译时间,你可以添加标志
j2
同时运行两个并行构建。这可能会减少到看一部电影;)
这篇文章已经有一段时间了,我想我应该添加一些关于如何在特定的硬件上尽可能快地构建Boost的内容。
如果你有4核或6核,分别使用-j5或-j7。当然不是标准版本,也不是-j2,除非你确实有双核。
我在我的主站上运行了一个3930K(6核)库存的Sandy Bridge Extreme,但在旧的备份盒上有一个2600k(4核),趋势是我用N + 1构建进程获得了最佳的Boost编译时间,其中N是物理内核的数量。N+2达到收益递减点,时间增加。
注:超线程启用,32GB内存DDR3,三星840 EVO SSD。
-j7在6核(2分51秒)(Win7终极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
-j6在6核(3分2秒)(Win7终极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
-j8在6核(3分17秒)(Win7终极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
配置
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)
我注意到64位构建需要更长的时间,我需要对这些进行相同的比较和更新。
一个简单的例子,让你开始在Visual Studio:
1.从这里下载并解压Boost。
2.创建一个Visual Studio空项目,使用一个不需要单独编译的示例boost库:
#include <iostream>
#include <boost/format.hpp>
using namespace std;
using namespace boost;
int main()
{
unsigned int arr[5] = { 0x05, 0x04, 0xAA, 0x0F, 0x0D };
cout << format("%02X-%02X-%02X-%02X-%02X")
% arr[0]
% arr[1]
% arr[2]
% arr[3]
% arr[4]
<< endl;
}
3.在Visual Studio项目属性中设置附加包含目录:
举个简单的例子:
如何在Visual Studio中安装Boost库
如果你不想使用整个boost库,只使用一个子集:
使用Windows中的boost库的子集
如果你现在特别想了解需要编译的库:
如何在Windows中使用Boost编译库
您还可以尝试-j%NUMBER_OF_PROCESSORS%作为参数,它将使用所有的内核。让我的四核速度超快。
推荐文章
- 为什么这个结合赋值和相等检查的if语句返回true?
- cplusplus.com给出的错误、误解或坏建议是什么?
- 找出质数最快的算法是什么?
- c++枚举类可以有方法吗?
- 格式化IO函数(*printf / *scanf)中的转换说明符%i和%d之间的区别是什么?
- 将析构函数设为私有有什么用?
- main()中的Return语句vs exit()
- 为什么c#不提供c++风格的'friend'关键字?
- 在函数的签名中添加关键字
- 我如何在Visual Studio中预处理后看到C/ c++源文件?
- 为什么在标准容器中使用std::auto_ptr<>是错误的?
- 用比较double和0
- Visual Studio 2010 - c++项目-删除*。自卫队文件
- 保护可执行文件不受逆向工程的影响?
- 在c++中字符串前面的“L”是什么意思?