关于如何在Visual Studio的空项目中使用Boost库的一步一步的解释是什么?
当前回答
下面是我使用Boost的方法:
下载并解压zip版本的Boost库。 运行bootstrap.bat文件,然后运行bjam.exe。 等待大约30分钟左右。 在Visual Studio中创建一个新项目。 转到项目——>属性——>连接器——>通用——>附加库目录,并将boost/stage/lib目录添加到其中。 转到项目——>属性——>C/ c++——>通用——>附加包括目录并添加boost目录。
您将能够毫无错误地构建您的项目!
其他回答
虽然Boost网站上的说明很有帮助,但这里有一个简化版本,也可以构建x64库。
只有在使用说明页第3节中提到的其中一个库时才需要这样做。(例如,使用Boost。文件系统需要编译。)如果您不使用其中任何一个,只需解压缩并运行。
构建32位库
这将安装C:\Boost\include\ Boost -(version)下的Boost头文件,以及C:\Boost\lib\i386下的32位库。请注意,库的默认位置是C:\Boost\lib,但如果您计划为多个体系结构构建,则需要将它们放在i386目录下。
解压缩Boost到一个新目录。 启动32位MSVC命令提示符,并切换到解压缩Boost的目录。 运行:引导 运行命令:b2 toolset=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)添加到include路径中。 将C:\Boost\lib\i386添加到libs路径。
构建64位库
这将安装C:\Boost\include\ Boost -(version)下的Boost头文件,以及C:\Boost\lib\x64下的64位库。请注意,库的默认位置是C:\Boost\lib,但如果您计划为多个体系结构构建,则需要将它们放在x64目录下。
解压缩Boost到一个新目录。 启动64位MSVC命令提示符,并切换到解压缩Boost的目录。 运行:引导 运行命令:b2 toolset=msvc-12.0——build-type=complete——libdir=C:\Boost\lib\x64 architecture=x86 address-model=64 install 对于Visual Studio 2012,请使用toolset=msvc-11.0 对于Visual Studio 2010,使用toolset=msvc-10.0 将C:\Boost\include\ Boost -(version)添加到include路径中。 将C:\Boost\lib\x64添加到libs路径中。
下载促进: http://www.boost.org/users/download/ 例如:SVN
Windows ->乌龟(最简单的方法)
之后: cmd ->进入boost目录(“D:\boostTrunk”-在那里您签出或下载并提取包): 命令: 引导
我们创建了bjam.exe在("D:\boostTrunk") 之后: 命令: Bjam toolset=msvc-10.0 variant=debug,release threading=multi link=static (大概需要20分钟左右)
后: 打开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;
}
资源: https://www.youtube.com/watch?v=5AmwIwedTCM
这里的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).
好运!
还有一个小提示:如果你想减少编译时间,你可以添加标志
j2
同时运行两个并行构建。这可能会减少到看一部电影;)
下面是我使用Boost的方法:
下载并解压zip版本的Boost库。 运行bootstrap.bat文件,然后运行bjam.exe。 等待大约30分钟左右。 在Visual Studio中创建一个新项目。 转到项目——>属性——>连接器——>通用——>附加库目录,并将boost/stage/lib目录添加到其中。 转到项目——>属性——>C/ c++——>通用——>附加包括目录并添加boost目录。
您将能够毫无错误地构建您的项目!