关于如何在Visual Studio的空项目中使用Boost库的一步一步的解释是什么?
当前回答
虽然Nate的回答已经很好了,但我将根据要求更具体地为Visual Studio 2010展开它,并包括在需要外部库的各种可选组件中编译的信息。
如果您只使用头文件库,那么您所需要做的就是解压缩boost下载并设置环境变量。下面的指令仅为Visual Studio设置环境变量,而不是在整个系统中设置。注意你只需要做一次。
Unarchive the latest version of boost (1.47.0 as of writing) into a directory of your choice (e.g. C:\boost_1_47_0). Create a new empty project in Visual Studio. Open the Property Manager and expand one of the configuration for the platform of your choice. Select & right click Microsoft.Cpp.<Platform>.user, and select Properties to open the Property Page for edit. Select VC++ Directories on the left. Edit the Include Directories section to include the path to your boost source files. Repeat steps 3 - 6 for different platform of your choice if needed.
如果您想使用boost中需要构建的部分,但不需要任何需要外部依赖的特性,那么构建它相当简单。
将最新版本的boost(编写时为1.47.0)解压缩到您选择的目录(例如C:\boost_1_47_0)。 启动所选平台的Visual Studio命令提示符,并导航到boost所在的位置。 运行:bootstrap.bat来构建b2.exe(以前命名为bjam)。 b2运行: Win32: b2——toolset=msvc-10.0——build-type=完成阶段; X64: b2——toolset=msvc-10.0——build-type=完整架构=x86 address-model=64 stage
去散步/看电影或2 / ....
执行上述指令集中的步骤2 - 6来设置环境变量。 编辑库目录部分,以包括到boost库输出的路径。(上面的示例和指令的默认值是C:\boost_1_47_0\stage\lib。如果你想让x86和x64并排(例如到<BOOST_PATH>\lib\x86 & <BOOST_PATH>\lib\x64),先重命名并移动目录。 重复步骤2 - 6为不同的平台,您的选择,如果需要。
如果您需要可选组件,那么您有更多的工作要做。这些都是:
提振。IOStreams Bzip2过滤器 提振。IOStreams Zlib过滤器 提振。MPI 提振。Python 提振。Regex ICU支持
Boost。IOStreams Bzip2过滤器:
将最新版本的bzip2库(编写时为1.0.6)源文件解压缩到您选择的目录(例如C:\bzip2-1.0.6)。 按照上面的第二组指令构建boost,但是在第5步中运行b2时添加选项-sBZIP2_SOURCE="C:\bzip2-1.0.6"。
提振。IOStreams Zlib过滤器
将最新版本的zlib库(编写时为1.2.5)源文件解压缩到您选择的目录(例如C:\zlib-1.2.5)。 按照上面的第二组指令构建boost,但是在第5步中运行b2时添加选项-sZLIB_SOURCE="C:\zlib-1.2.5"。
提振。MPI
Install a MPI distribution such as Microsoft Compute Cluster Pack. Follow steps 1 - 3 from the second set of instructions above to build boost. Edit the file project-config.jam in the directory <BOOST_PATH> that resulted from running bootstrap. Add in a line that read using mpi ; (note the space before the ';'). Follow the rest of the steps from the second set of instructions above to build boost. If auto-detection of the MPI installation fail, then you'll need to look for and modify the appropriate build file to look for MPI in the right place.
提振。Python
Install a Python distribution such as ActiveState's ActivePython. Make sure the Python installation is in your PATH. To completely built the 32-bits version of the library requires 32-bits Python, and similarly for the 64-bits version. If you have multiple versions installed for such reason, you'll need to tell b2 where to find specific version and when to use which one. One way to do that would be to edit the file project-config.jam in the directory <BOOST_PATH> that resulted from running bootstrap. Add in the following two lines adjusting as appropriate for your Python installation paths & versions (note the space before the ';'). using python : 2.6 : C:\\Python\\Python26\\python ; using python : 2.6 : C:\\Python\\Python26-x64\\python : : : <address-model>64 ; Do note that such explicit Python specification currently cause MPI build to fail. So you'll need to do some separate building with and without specification to build everything if you're building MPI as well. Follow the second set of instructions above to build boost.
提振。Regex ICU支持
Unarchive the latest version of ICU4C library (4.8 as of writing) source file into a directory of your choice (e.g. C:\icu4c-4_8). Open the Visual Studio Solution in <ICU_PATH>\source\allinone. Build All for both debug & release configuration for the platform of your choice. There can be a problem building recent releases of ICU4C with Visual Studio 2010 when the output for both debug & release build are in the same directory (which is the default behaviour). A possible workaround is to do a Build All (of debug build say) and then do a Rebuild all in the 2nd configuration (e.g. release build). If building for x64, you'll need to be running x64 OS as there's post build steps that involves running some of the 64-bits application that it's building. Optionally remove the source directory when you're done. Follow the second set of instructions above to build boost, but add in the option -sICU_PATH="C:\icu4c-4_8" when running b2 in step 5.
其他回答
我可以推荐以下技巧:创造一种特殊的刺激。道具文件
打开物业管理 右键单击项目节点,选择“添加新项目属性表”。 选择一个位置并命名您的属性表(例如: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\目录中。
您还可以尝试-j%NUMBER_OF_PROCESSORS%作为参数,它将使用所有的内核。让我的四核速度超快。
下载促进: 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
还有一个小提示:如果你想减少编译时间,你可以添加标志
j2
同时运行两个并行构建。这可能会减少到看一部电影;)
虽然Nate的回答已经很好了,但我将根据要求更具体地为Visual Studio 2010展开它,并包括在需要外部库的各种可选组件中编译的信息。
如果您只使用头文件库,那么您所需要做的就是解压缩boost下载并设置环境变量。下面的指令仅为Visual Studio设置环境变量,而不是在整个系统中设置。注意你只需要做一次。
Unarchive the latest version of boost (1.47.0 as of writing) into a directory of your choice (e.g. C:\boost_1_47_0). Create a new empty project in Visual Studio. Open the Property Manager and expand one of the configuration for the platform of your choice. Select & right click Microsoft.Cpp.<Platform>.user, and select Properties to open the Property Page for edit. Select VC++ Directories on the left. Edit the Include Directories section to include the path to your boost source files. Repeat steps 3 - 6 for different platform of your choice if needed.
如果您想使用boost中需要构建的部分,但不需要任何需要外部依赖的特性,那么构建它相当简单。
将最新版本的boost(编写时为1.47.0)解压缩到您选择的目录(例如C:\boost_1_47_0)。 启动所选平台的Visual Studio命令提示符,并导航到boost所在的位置。 运行:bootstrap.bat来构建b2.exe(以前命名为bjam)。 b2运行: Win32: b2——toolset=msvc-10.0——build-type=完成阶段; X64: b2——toolset=msvc-10.0——build-type=完整架构=x86 address-model=64 stage
去散步/看电影或2 / ....
执行上述指令集中的步骤2 - 6来设置环境变量。 编辑库目录部分,以包括到boost库输出的路径。(上面的示例和指令的默认值是C:\boost_1_47_0\stage\lib。如果你想让x86和x64并排(例如到<BOOST_PATH>\lib\x86 & <BOOST_PATH>\lib\x64),先重命名并移动目录。 重复步骤2 - 6为不同的平台,您的选择,如果需要。
如果您需要可选组件,那么您有更多的工作要做。这些都是:
提振。IOStreams Bzip2过滤器 提振。IOStreams Zlib过滤器 提振。MPI 提振。Python 提振。Regex ICU支持
Boost。IOStreams Bzip2过滤器:
将最新版本的bzip2库(编写时为1.0.6)源文件解压缩到您选择的目录(例如C:\bzip2-1.0.6)。 按照上面的第二组指令构建boost,但是在第5步中运行b2时添加选项-sBZIP2_SOURCE="C:\bzip2-1.0.6"。
提振。IOStreams Zlib过滤器
将最新版本的zlib库(编写时为1.2.5)源文件解压缩到您选择的目录(例如C:\zlib-1.2.5)。 按照上面的第二组指令构建boost,但是在第5步中运行b2时添加选项-sZLIB_SOURCE="C:\zlib-1.2.5"。
提振。MPI
Install a MPI distribution such as Microsoft Compute Cluster Pack. Follow steps 1 - 3 from the second set of instructions above to build boost. Edit the file project-config.jam in the directory <BOOST_PATH> that resulted from running bootstrap. Add in a line that read using mpi ; (note the space before the ';'). Follow the rest of the steps from the second set of instructions above to build boost. If auto-detection of the MPI installation fail, then you'll need to look for and modify the appropriate build file to look for MPI in the right place.
提振。Python
Install a Python distribution such as ActiveState's ActivePython. Make sure the Python installation is in your PATH. To completely built the 32-bits version of the library requires 32-bits Python, and similarly for the 64-bits version. If you have multiple versions installed for such reason, you'll need to tell b2 where to find specific version and when to use which one. One way to do that would be to edit the file project-config.jam in the directory <BOOST_PATH> that resulted from running bootstrap. Add in the following two lines adjusting as appropriate for your Python installation paths & versions (note the space before the ';'). using python : 2.6 : C:\\Python\\Python26\\python ; using python : 2.6 : C:\\Python\\Python26-x64\\python : : : <address-model>64 ; Do note that such explicit Python specification currently cause MPI build to fail. So you'll need to do some separate building with and without specification to build everything if you're building MPI as well. Follow the second set of instructions above to build boost.
提振。Regex ICU支持
Unarchive the latest version of ICU4C library (4.8 as of writing) source file into a directory of your choice (e.g. C:\icu4c-4_8). Open the Visual Studio Solution in <ICU_PATH>\source\allinone. Build All for both debug & release configuration for the platform of your choice. There can be a problem building recent releases of ICU4C with Visual Studio 2010 when the output for both debug & release build are in the same directory (which is the default behaviour). A possible workaround is to do a Build All (of debug build say) and then do a Rebuild all in the 2nd configuration (e.g. release build). If building for x64, you'll need to be running x64 OS as there's post build steps that involves running some of the 64-bits application that it's building. Optionally remove the source directory when you're done. Follow the second set of instructions above to build boost, but add in the option -sICU_PATH="C:\icu4c-4_8" when running b2 in step 5.