VC6下使用STLPort

本文详细介绍如何在Visual Studio环境下编译和使用STLport库。包括下载STLport源码、配置编译环境变量、编译静态和动态链接库等步骤,并提供了hash_map示例代码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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
<int,string>mymap;
mymap[
2008]="VC6";
mymap[
999999]="STLport";
mymap[
123456]="hellohash_map!";
hash_map
<int,string>::iteratoriter=mymap.find(123456);
if(iter!=mymap.end())
{
cout
<<iter->second<<endl;
}

return0;
}

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安装目录
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值