<boost -01> boost::filesystem在visual studio 2015的安装/配置方法
2016-09-04 11:47
411 查看
笔者为了方便地在vs中使用c++方便地进行文件/文件夹操作,需要安装使用boost::filesystem; 百度经验“怎样在VS2013中安装配置boost_1_55_0库”介绍非常详细,笔者之前在vs2013(x86)按照说明进行安装时一次成功,但是在vs2015(x64)环境下遇到一些问题,最后得到解决,现在遇到问题及解决方法做一汇总,以方便其他人;
安装环境
系统平台(win7-x64)
[visual studio 2015 community(社区版)](安装包下载)(https://www.microsoft.com/en-us/download/details.aspx?id=48146)
boost::filesystem 1-61
安装过程
下载boost安装包,笔者使用boost_1_61_0;
解压文件包到本地目录(笔者安装目录为
命令运行完成后,会在boost安装目录下出现
在命令窗口中输入
在工程中添加包含目录:进入Property Manager(属性管理器)->Property(属性)->Common Properties(通用属性)->C/C++ ->General(常规)->Additional Include Directories(附加包含目录)-> 添加boost文件夹目录(我添加的是C:\boost_1_61_0);
在工程中添加库目录:进入Property Manager(属性管理器)->Property(属性)->Common Properties(通用属性)->Linker(链接器) ->General(常规)->Additional Library Directories(附加库目录)-> 添加boost文件夹库目录(我添加的是C:\boost_1_61_0\stage\lib);
验证程序:在vs中新建空项目,在源文件(source files)添加cpp文件,cpp文件中复制程序;运行后,C盘中所有目录会显示在控制台上(console);如果运行成功,则说明配置正常;
4.常见问题:
1. Error-1
;解决方案,是需要生成不同的run time check 文件;使用
fatal error LNK1112: module machine type ‘X86’ conflicts with target
machine type ‘x64’
解决方法:需要为编译vs(x64)所需要的文件;具体做法是在安装过程第四部运行
5 . 参考资料
1. “How to use Boost in Visual Studio 2010” 来自 stack overflow;非常详细地介绍了安装过程;
2. “怎样在VS2013中安装配置boost_1_55_0库 ”来自百度经验;
3. “64-bit version of Boost for 64-bit window
4000
s”来自 stack overflow;
4. “2>LINK : fatal error LNK1104: cannot open file ‘libboost_filesystem-vc120-mt-sgd-1_58.lib’”来自 stack overflow;
安装环境
系统平台(win7-x64)
[visual studio 2015 community(社区版)](安装包下载)(https://www.microsoft.com/en-us/download/details.aspx?id=48146)
boost::filesystem 1-61
安装过程
下载boost安装包,笔者使用boost_1_61_0;
解压文件包到本地目录(笔者安装目录为
C:\boost_1_61_0,应避免目录中出现空格); 打开cmd窗口, 使用
cd命令进入到boost安装目录(
cd C:\boost_1_61_0需要根据实际情况改变安装目录),进而运行文件夹下的
bootstrap.bat文件;
命令运行完成后,会在boost安装目录下出现
bjam.exe文件;
在命令窗口中输入
bjam.exe;此过程中将编译lib文件和头文件;
在工程中添加包含目录:进入Property Manager(属性管理器)->Property(属性)->Common Properties(通用属性)->C/C++ ->General(常规)->Additional Include Directories(附加包含目录)-> 添加boost文件夹目录(我添加的是C:\boost_1_61_0);
在工程中添加库目录:进入Property Manager(属性管理器)->Property(属性)->Common Properties(通用属性)->Linker(链接器) ->General(常规)->Additional Library Directories(附加库目录)-> 添加boost文件夹库目录(我添加的是C:\boost_1_61_0\stage\lib);
验证程序:在vs中新建空项目,在源文件(source files)添加cpp文件,cpp文件中复制程序;运行后,C盘中所有目录会显示在控制台上(console);如果运行成功,则说明配置正常;
#include<boost\filesystem.hpp> #include<iostream> namespace fs = boost::filesystem; int get_subfolders(const std::string& dir, std::vector<std::string>& filenames); int main() { const std::string dir = "C:\\"; std::vector<std::string> filenames; int fileCount = get_subfolders(dir, filenames); std::vector<std::string >::iterator iter = filenames.begin(); std::vector<std::string>::iterator itend = filenames.end(); for (; iter != itend; iter++) { std::cout << (*iter) << std::endl; } std::cout << filenames.size() << std::endl; return filenames.size(); } int get_subfolders(const std::string& dir, std::vector<std::string>& filenames) { fs::path path(dir); if (!fs::exists(path)) { return -1; } fs::directory_iterator end_iter; for (fs::directory_iterator iter(path); iter != end_iter; ++iter) { if (fs::is_directory(iter->status())) { filenames.push_back(iter->path().string()); } } return filenames.size(); }
4.常见问题:
1. Error-1
LINK : fatal error LNK1104: cannot open file 'libboost_filesystem-vc120-mt-sgd-1_58.lib'
;解决方案,是需要生成不同的run time check 文件;使用
b2指令,输入代码
b2 runtime-link=static runtime-debugging=on variant=debug;参考资料3和4 ;
2. Error-2:
fatal error LNK1112: module machine type ‘X86’ conflicts with target
machine type ‘x64’
解决方法:需要为编译vs(x64)所需要的文件;具体做法是在安装过程第四部运行
bjam时候,添加相应的说明;需要注意的是代码中需要输入正确的vs版本号;如vs2015,那么下述代码中的
msvc-9.09.0应该改为
msvc-9.014.0; 具体请见参考文献3 “
64-bit version of Boost for 64-bit windows”;
bjam --toolset=msvc-9.0 address-model=64 --build-type=complete stage
5 . 参考资料
1. “How to use Boost in Visual Studio 2010” 来自 stack overflow;非常详细地介绍了安装过程;
2. “怎样在VS2013中安装配置boost_1_55_0库 ”来自百度经验;
3. “64-bit version of Boost for 64-bit window
4000
s”来自 stack overflow;
4. “2>LINK : fatal error LNK1104: cannot open file ‘libboost_filesystem-vc120-mt-sgd-1_58.lib’”来自 stack overflow;
相关文章推荐
- Visual Studio 2015 Update 1 成功安装后运行 “出现未能正确加载[XXXX]包,此问题可能是由配置更改或安装另一个扩展导致的。” 可能的解决方法
- <JAVA>Hadoop安装配置(单机)
- Boost-Visual studio 2015环境配置
- <转>雅虎开源TensorflowOnSpark,Ubuntu配置安装TensorflowOnSpark
- Myeclipse2015 Jrebel插件的安装、配置、使用(新建.java文件、给类添加新方法、新属性、修改代码等,不用重启tomcat即可更新)
- Visual Studio 2015中 没有“安装和部署”的解决方法
- <转载>在Win7下硬盘安装ubuntu9.10方法小结
- <配置> Ubuntu gcc 安装 使用方法
- Centos7中anaconda的安装配置之忘记添加环境变量怎么办-->XGboost安装-->vi退出
- visual studio 2012安装配置方法图文教程 附opencv配置教程
- Visual Studio 2015 Update 1 安装到最后 KB3022398 错误解决方法
- Visual Studio 2015编译安装配置QT5.5.1(含QTWEBKIT)
- Visual Studio 2015编译安装配置QT5.5.1(含QTWEBKIT)
- [No00009D]使用visual studio 2015 update3打包程序安装包的简单方法(不需要InstallShield)
- <转>Nagios安装及配置
- Spring配置文件中使用ref local与ref bean的区别. 在ApplicationResources.properties文件中,使用<ref bean>与<ref local>方法如下
- Spring配置文件中使用ref local与ref bean的区别. 在ApplicationResources.properties文件中,使用<ref bean>与<ref local>方法如下
- Visual Studio 2015 出现 NuGet 安装程序包错误解决方法
- <转载> nginx服务器安装及配置文件详解 https://segmentfault.com/a/1190000002797601
- Visual Studio 2015编译安装配置QT5.5.1(含QTWEBKIT)