现在的位置: 首页 > 综合 > 正文

(转)vs2008+stlport+boost配置

2012年04月05日 ⁄ 综合 ⁄ 共 2055字 ⁄ 字号 评论关闭

转自:http://www.sicaril.com/forum.php?mod=viewthread&tid=2083&extra=)vs2008+stlport+boost

一.编译STLPort

1、从STLPort官网http://www.stlport.org/下载STLport-5.2.1.tar.bz2,将其解压到硬盘任何位置,如 D:/STLport-5.2.1。

2、进入Visual Studio 2008命令行,执行命令cd D:/STLport5.2.1进入STLPort的根目录。

3、执行命令configue msvc9配置编译环境。

6、执行命令cd D:/STLport5.2.1/lib。

7、执行命令nmake –f msvc.mak clean install,编译STLport。

编译完成后在STLPort主目录D:/STLport5.2.1下面生成了lib和bin两个文件夹,所有编译产生的*.dll和*.lib文件都已经复制到这两个文件夹,删除D:/STLport5.2.1/build/lib目录下产生的obj文件夹以节约硬盘空间。

二.编译Boost1_47_0

1、从boost官网http://www.boost.org/下载boost_1_47_0.7z,将其解压到硬盘任何位置,如 D:/boost_1_47_0。

2、进入Visual Studio 2008命令行,执行命令cd D:/boost_1_47_0进入boost的根目录,运行批处理文件bootstrap.bat,生成编译boost库的工具bjam.exe。

3、修改Boost配置文件。

   进入文件夹D:/boost_1_47_0/tools/build/v2编辑文件user-config.jam。

   找到文件中的MSVC configuration处, 将# using msvc : 8.0 ;修改为using msvc : 9.0 ; (记得去掉代表注释的#号),

   找到文件中的STLPort configuration处,将# using stlport : : /usr/include/stlport /usr/lib ;修改为 using stlport : 5.2.1 : "D:/STLport-5.2.1/stlport" : "D:/STLport-5.2.1/lib" ;

4、执行完全编译boost库的命令 bjam --toolset=msvc --build-type=complete stdlib=stlport stage(可以根据自己的需求更改bjam工具的编译参数)。

接下来等待boost编译过程完成。编译完成后,所有boost库文件都默认编译到文件夹D:/boost_1_47_0/stage/lib中,另外boost的头文件所在文件夹就是D:\boost_1_47_0\boost。删除D:\boost_1_47_0\bin.v2节约硬盘空间。

三、  VS2008环境配置

1、打开菜单 VS2008->工具->选项,在“项目和解决方案”的“VC++目录”页,选择“包含文件”,加入D:\STLport5.2.1\stlport和D:\boost_1_47_0,并调到最前面;选择“库文件”,加入D:\STLport5.2.1\lib和D:\boost_1_47_0\stage\lib,并调到最前面。

2、设置工程属性

    打开菜单 项目->属性, 在“配置属性”的“常规”页,设置字符集为“未设置”。

    在“C/C++”的“代码生成”页,选择运行库为多线程(release版是/MT,Debug版为/MTd)。
   
    若是Debug版工程,不要忘记在预处理器页中定义宏“_STLP_DEBUG”和“__STL_DEBUG”(注意此处开头的下划线是双下划线)以使用STLport。

    另外,与MFC配合使用,需要定义宏“_STLP_USE_MFC”。

四、给出一小段测试代码

#include <iostream>   
#include <vector>  
#include <boost/timer.hpp>  

using namespace std;   
using namespace boost;   

int main()   
{      
    std::vector<int> vt;  //STLport的vector!  
    timer t;    //构造一个计时器对象        
    cout<<"max timespan:"<<t.elapsed_max()/3600<<"h"<<endl; //定时器最大计时        
    cout<<"min timespan:"<<t.elapsed_min()<<"s"<<endl;      //定时器最小计时(分辨率)         

    cout<<"now time elapsed:"<<t.elapsed()<<"s"<<endl;      //从计时器对象构建至今过了多长时间      

    system( "pause" );  
    return 0;   
}

抱歉!评论已关闭.