在win7 + vs express for desktop中安装stlport和boost库
一、安装stlport
stlport是将sgi的stl库平移到各个平台上。sgi的这个库的特点就是效率非常高。boost在这个库上面运行要比vs自带的stl库效率高。所以我们首选安装stlport。
下载stlport: 最新版本是5.2.1
放到C盘根目录下面,解压。进入”vs2012 x86 native tools command prompt”。(注意:用cmd不行)
进入“C:\STLPort”目录,运行命令“configure msvc9”。msvc9应该对应的是vs2008。现在stlport没有支持更高的vs版本。所以,就按msvc9来configure了。
“cd C:\STLport\lib”,运行“nmake -f msvc.mak clean install”。
这个时候会出现错误,如下:
*C:\STLport\stlport\stl/_cstdlib.h(158): error C2084: function ‘__int64 abs(__int64)’ already has a body
C:\Program Files\Microsoft Visual Studio 10.0\VC\INCLUDE../include/stdlib.h(471) : see previous definition of ‘abs’
NMAKE : fatal error U1077: ‘“C:\ProgramFiles\Microsoft Visual Studio 10.0\VC\BIN\cl.EXE”’ : return code ‘0x2’*
解决方法是找到“C:\STLport\stlport\stl_cstdlib.h”文件,在158行中,由
inline _STLP_LONG_LONG abs(_STLP_LONG_LONG __x) { return __x < 0 ? -__x : __x; }改成:
# if !defined(_STLP_MSVC) || (_STLP_MSVC < 1600) inline _STLP_LONG_LONG abs(_STLP_LONG_LONG __x) { return __x < 0 ? -__x : __x; } # endif不出意外的话,等待二十分钟,应该就会编译完成。
删除“STLport\build\lib\obj”目录中的中间文件(大约300M),节省磁盘工件
设置vs,优先使用stlport的头文件和lib库
首先需要打开一个project
选择 菜单“project–>xx properties…”
在顶部下拉菜单中选择“configuration: All configurations”,否则每次创建新的project都要设置一次,烦死~
找到“configuration properties –> vc++ directories”
修改三个目录:“include directories”,,加入“C:\STLPort\stlport”;“library directories”加入“C:\STLPort\lib”;“excutable directories”加入“C:\STLPort\bin”
找到“configuration properties –> General–>Character Set”,设置为“Not Set”
找到“configuration properties –>Preprocessor–> Preprocessor Definitions”,加入“_STLP_DEBUG”和“__STL_DEBUG”,这样在debug的时候,就能够动态链接到stlport的debug版本的库了,能够深入debug进去。
找到“configuration properties –>Preprocessor–> Code Generation–> Runtime Library”,设置成“Multi Thread”。*要注意区分debug版本和release版本,分别对应不同的编译target。
二、安装boost库
boost提供一些stl没有的功能,如:多线程、正则表达式、函数式编程、等等。据说boost要被收录进stl成为标准。
下载boost库: 现在的最新版本是1.58.0
放到C盘根目录下解压,得到“C:\boost”(改了目录名字,去除了版本号)
用”vs2012 x86 native tools command prompt”进入上面目录,运行批处理文件:“bootstrap.bat”,在“C:\boost”目录下生成b2.exe,bjam.exe,和project-config.jam
用文本编辑器打开project-config.jam文件,并修改,增加一行“using stlport : STLport : C:/STLport/stlport : C:/STLport/lib ;”以便使用stlport作为底层库进行编译。注意:路径之间用冒号分隔,而不是分号或者空格;上面增加的两个路径分别是头文件路径和lib库路径。
键入命令“bjam threading=multi link=shared,static runtime-link=shared stdlib=stlport –stagedir=./stage”进行编译……漫长的等待
编译完成。在我的机器上,failed updated 658 targets, skipped 808 targets, updated 813 targets……
继续设置project以便能够利用boost库中的文件和编译出来的结果
首先需要打开一个project
选择 菜单“project–>xx properties…”
在顶部下拉菜单中选择“configuration: All configurations”
找到“configuration properties –> C/C++->General->Additional Include Directories”,设置boost头文件路径,“C:\boost\boost”
找到“configuration properties –> C/C++->linker->Additional library Directories”,设置boost库文件路径,“C:\boost\stage\lib”。之前老版本,需要从编译好的路径里面copy&paste出来这些库,不过现在貌似都生成在stage目录下了。
三、尝试
从网上找一段代码如下:
温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/70415.html