关于如何在Visual Studio中的空项目中使用Boost库的逐步说明,有什么很好的解释? html
这是我如何使用Boost的方法: ios
您将可以构建您的项目而不会出现任何错误! bootstrap
从如下网址下载加强功能: http : //www.boost.org/users/download/,例如svn windows
以后:cmd->转到boost目录(“ D:\\ boostTrunk”-您在其中签出或下载并解压缩包):command: bootstrap svn
咱们在(“ D:\\ boostTrunk”)中建立了bjam.exe:以后:命令: bjam toolset = msvc-10.0 variant = debug,release threading = multi link = static (这须要一些时间〜20min。) visual-studio
以后:打开Visual Studio 2010->建立空项目->转到项目属性->设置: 网站
粘贴此代码,而后检查其是否有效? ui
#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; }
资源: https : //www.youtube.com/watch?v=5AmwIwedTCM spa
一个使您开始使用Visual Studio的极简示例: debug
1.今后处下载并解压Boost。
2.使用示例boost库建立一个Visual Studio空项目,该示例不须要单独编译:
#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项目属性中,设置“附加包含目录”:
举一个很是简单的例子:
若是您不想使用整个Boost库,请使用如下子集:
若是您如今特别想了解须要编译的库:
您须要Boost的哪些部分? Visual Studio随附的TR1包含不少内容,所以您能够简单地说,例如:
#include <tr1/memory> using std::tr1::shared_ptr;
根据James的说法,这在C ++ 0x中也应该起做用:
#include <memory> using std::shared_ptr;
虽然说明书上的升压网站是有帮助的,这里是一个浓缩版,也是创建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路径。