VC6下使用STLPort

来源:互联网 发布:mac访问nas共享文件夹 编辑:程序博客网 时间:2024/05/21 20:21

1. STLport下载:http://www.stlport.org/
      我下载的是最新版  02.25.07: STLport 5.1.2 released

2. STLport编译:
      我的STLport目录是:D:/STLport-5.1.2
      先设置一下VC6下的环境变量:C:/Program Files/Microsoft Visual Studio/VC98/Bin/VCVARS32.BAT
     把D:/STLport-5.1.2/stlport;加入Include路径中;把D:/STLport-5.1.2/lib;加入Lib路径中
      在命令行窗口下:
      运行VCVARS32.BAT,然后
      cd D:/STLport-5.1.2/build/lib
      configure -c msvc6
      nmake /fmsvc.mak install
      编译全部用的默认选项,因此编译出来的是多线程静态链接库。库文件被拷贝到D:/STLport-5.1.2/lib

3. 在VC6中使用STLport:
      Tools->Options...->Directories中
      include设置中添加目录:D:/STLport-5.1.2/stlport
      library设置中添加目录:D:/STLport-5.1.2/lib
      Project->Settings...->C/C++中
      Category选择Code Generation,然后在use run-time library中选择Debug Multithreaded。(如果是release版本,选择Multithreaded;如果想用动态链接,则要先编译动态链接版本的STLport,再在这儿选择相应的DLL)

4. hash_map的例子:

#include <iostream>
#include 
<hash_map>
#include 
<string>

using namespace std;

int main()
{
    hash_map
<intstring> mymap;
    mymap[
2008]="VC6";
    mymap[
999999]="STLport";
    mymap[
123456]="hello hash_map!";
    hash_map
<intstring>::iterator iter = mymap.find(123456);
    
if(iter != mymap.end())
    
{
        cout
<<iter->second<<endl;
    }

    
return 0;
}

 

 

 

stlport 5.10 编译 更加容易了(visual studio 2005)

运行命令提示符
进入%stlport%/build/lib目录
configure --help
此时会列出配置参数,其中:
-c <compiler> :配置所用的编译器,列表如下:
   msvc6    Microsoft Visual C++ 6.0
   msvc7    Microsoft Visual C++ .NET 2002
   msvc71   Microsoft Visual C++ .NET 2003
   msvc8    Microsoft Visual C++ 2005
   icl      Intel C++ Compiler
   evc3     Microsoft eMbedded Visual C++ 3 (*)
   evc4     Microsoft eMbedded Visual C++ .NET (*)
   evc8     Microsoft Visual C++ 2005 compiling for CE
   gcc      GNU C++ Compiler (MinGW package)
   dmc      Digital Mars Compiler
   bcc      Borland C++ Compiler
我使用的是2005,所以使用:
-c msvc8

--rtl-static:编译为静态库(项目属性选择/MT会用到这个产生的lib)
--rtl-dynamic:编译为动态库(项目属性选择/MD会用到这个产生的lib)

--use-boost <boost install path>:如果使用boost这填入boost的安装目录

--extra-cxxflag <additional compilation options>:需要传给cl编译程序的另外的命令
如 /arch:SSE (启用sse优化)  /arch:SSE2 (启用sse2优化)

几个重要的说完,我自己的配置命令是:
configure -c msvc8 --rtl-static --use-boost 我的boost目录

接着按提示
nmake /f msvc.mak clean
nmake /f msvc.mak
即完成了stl的编译

接下来将obj目录里生成的*.lib、*.dll、*.pdb、*.exp、*.dll.manifest复制到%stlport%/lib
windows path环境变量最后添加;%stlport%/lib

然后在visual studio的include目录添加%stlport%/stlport目录
                     lib    目录添加%stlport%/lib    目录

即可正常使用stlport了

注:%stlport%即指stlport安装目录