C++ 如何在VisualStudio2010中使用Boost
关于如何在VisualStudio中的空项目中使用Boost库,有什么好的逐步解释吗?您需要Boost的哪些部分?很多东西都是VisualStudio附带的TR1的一部分,因此您可以简单地说,例如:C++ 如何在VisualStudio2010中使用Boost,c++,visual-studio-2010,boost,C++,Visual Studio 2010,Boost,关于如何在VisualStudio中的空项目中使用Boost库,有什么好的逐步解释吗?您需要Boost的哪些部分?很多东西都是VisualStudio附带的TR1的一部分,因此您可以简单地说,例如: #include <tr1/memory> using std::tr1::shared_ptr; #包括 使用std::tr1::shared\u ptr; 根据James的说法,这也应该有效(在C++0x中): #包括 使用std::shared_ptr; 虽然Boost网站上
#include <tr1/memory>
using std::tr1::shared_ptr;
#包括
使用std::tr1::shared\u ptr;
根据James的说法,这也应该有效(在C++0x中):
#包括
使用std::shared_ptr;
虽然Boost网站上的有帮助,但这里有一个精简版,它也可以构建x64库
- 只有在使用“说明”页的中提到的某个库时,才需要执行此操作。(例如,要使用Boost.Filesystem需要编译。)如果您没有使用任何一个,只需解压缩即可
C:\Boost\include\Boost-(version)
下安装Boost头文件,并在C:\Boost\lib\i386
下安装32位库。请注意,库的默认位置是C:\Boost\lib
,但如果您计划为多个体系结构构建,则需要将它们放在i386
目录下
bootstrap
b2工具集=msvc-12.0--build type=complete--libdir=C:\Boost\lib\i386 install
- 对于Visual Studio 2012,请使用
toolset=msvc-11.0
- 对于Visual Studio 2010,请使用
toolset=msvc-10.0
- 对于Visual Studio 2017,请使用
toolset=msvc-14.1
C:\Boost\include\Boost-(version)
添加到包含路径C:\Boost\lib\i386
添加到您的libs路径C:\Boost\include\Boost-(version)
下安装Boost头文件,并在C:\Boost\lib\x64
下安装64位库。请注意,库的默认位置是C:\Boost\lib
,但如果您计划为多个体系结构构建,则需要将它们放在x64
目录下
bootstrap
b2工具集=msvc-12.0--构建类型=完成--libdir=C:\Boost\lib\x64架构=x86地址模型=64安装
- 对于Visual Studio 2012,请使用
toolset=msvc-11.0
- 对于Visual Studio 2010,请使用
toolset=msvc-10.0
C:\Boost\include\Boost-(version)
添加到包含路径C:\Boost\lib\x64
添加到您的libs路径C:\boost\u 1\u 47\u 0
)Microsoft.Cpp..user
,然后选择Properties
打开属性页进行编辑VC++目录
包含目录
部分以包含boost源文件的路径C:\boost\u 1\u 47\u 0
)bootstrap.bat
构建b2.exe(以前命名为bjam)- Win32:
李>b2——工具集=msvc-10.0——构建类型=完成阶段
- x64:
b2--toolset=msvc-10.0--build type=complete architecture=x86 address model=64 stage
库目录
部分以包括boost库输出的路径。(以上示例和说明的默认值为C:\boost\u 1\u 47\u 0\stage\lib
。如果希望x86和x64并排(例如to\lib\x86
&\lib\x64
),请先重命名并移动目录)- Boost.IOStreams Bzip2过滤器
- Boost.IOStreams Zlib滤波器
- Boost.MPI
- Python
- Boost.Regex ICU支持
C:\bzip2-1.0.6
)-sBZIP2_SOURCE=“C:\bzip2-1.0.6”
#include <memory>
using std::shared_ptr;
<?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>
#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;
}
#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;
}
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
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
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)