关于如何在Visual Studio的空项目中使用Boost库的一步一步的解释是什么?
当前回答
这篇文章已经有一段时间了,我想我应该添加一些关于如何在特定的硬件上尽可能快地构建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位构建需要更长的时间,我需要对这些进行相同的比较和更新。
其他回答
还有一个小提示:如果你想减少编译时间,你可以添加标志
j2
同时运行两个并行构建。这可能会减少到看一部电影;)
此外,还有一些东西我觉得很有用。为您的提升路径使用环境变量。(如何在窗口中设置环境变量,链接在底部7,8,10)BOOST_ROOT变量似乎是常见的地方了,它被设置为解压boost的根路径。
然后在属性,c++,通用,附加包含目录使用$(BOOST_ROOT)。然后,如果/当您移动到boost库的新版本时,您可以更新环境变量以指向这个新版本。随着你的项目越来越多,使用boost,你将不必为所有的项目更新“附加包含目录”。
您还可以创建一个BOOST_LIB变量,并将其指向库暂存的位置。同样地,对于链接器->附加库目录,您不必更新项目。我有一些旧的东西用vs10和vs14建立了新的东西,所以建立了两个口味的boost lib到同一个文件夹。所以如果我把一个项目从vs10移动到vs14,我不需要改变提升路径。
注意:如果你改变了一个环境变量,它不会突然在一个开放VS项目中工作。VS在启动时加载变量。所以你需要关闭VS然后重新打开它。
这篇文章已经有一段时间了,我想我应该添加一些关于如何在特定的硬件上尽可能快地构建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位构建需要更长的时间,我需要对这些进行相同的比较和更新。
这里的Windows安装程序非常适合我。我采取了以下步骤:
Follow the installation wizard until finished. Run visual studio. Create a new C++ project Open project properties (can be found by right-clicking the project name in the solution explorer) Under "C/C++ > General > Additional Include Directories" add the path where boost root directory. Default for my version was C:\local\boost_1_63_0. The number after "boost" is the version of boost. In project properties, under "Linker > Additional Library Directories" add the directory for library files. Default for my version was C:\local\boost_1_63_0\lib64-msvc-14.0. The number after "lib" is related to the build target (32 bit or 64 bit in Visual Studio) and the number after "msvc" is related to the version of Visual Studio (14.0 is related to Visual Studio 2015, but I'm using it with the 2017 Visual Studio).
好运!
你需要Boost的哪些部分?很多东西都是TR1的一部分,它是随Visual Studio一起发布的,所以你可以简单地说,例如:
#include <tr1/memory>
using std::tr1::shared_ptr;
根据James的说法,这也应该工作(在c++ 0x中):
#include <memory>
using std::shared_ptr;
推荐文章
- 为什么这个结合赋值和相等检查的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”是什么意思?