Boost_1_55_0+StlPort5.2.1+VS2010在xp环境搭建

一直以来都想学学网络库,可是一直都没有真正的把环境搭建好,自己买了一本boost网络库的书籍,折腾了几天之后还是没有搞定配置,今日刚好把手头的项目调试成功,下午有时间来调试环境了,参照了网络上的资料,最后折腾出来了,如下所述:

一、相关信息

平台:Windows xp sp3

软件:VS2010

网络库:Boost_1_55_0STLPort-5.2.1(点击下载)


二、安装配置STLPort-5.2.1

     1.将下载的STLport-5.2.1.tar.bz2解压至D:\opensource\STLport;

2.使用VS2010的命令运行bootstrap.bat生成bjam.exe可执行文件

点击开始—>所有程序--> Microsoft Visual Studio 2010-->VisualStudio tools--> Visual Studio 2010 command prompt       D:\Program Files\Microsoft Visual Studio 10.0\VC>  cd D:\opensource\STLport

3.修改编译文件_cstdlib.h(158)代码

		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

4.执行configure msvc9(configure msvc10 会显示 Unknown compiler: msvc10, msvc9即可)

   D:\opensource\STLport> onfigure msvc9

5.编译

  D:\opensource\STLport>  cd build/lib

       D:\opensource\STLport>  nmake clean install
6.应用

把 D:\STLport-5.2.1\bin下 stlport.5.2.dll,stlportd.5.2.dll,stlportstld.5.2.dll,复制到 C:\Program Files\Microsoft Visual Studio 10.0\VC\bin 目录下,这样vc就能找到它了

使用STLport除了向项目添加 STLport 的头文件目录和 Lib 目录以外还有如下宏定义配合使用。

1 #define _STLP_USE_STATIC_LIB   		 // 使用 STLport 静态库   
2 #define _STLP_USE_DYNAMIC_LIB // 使用 STLport 动态库
3 #define _STLP_DEBUG // STLport 启用 Debug 模式下的检查功能
4 #define _STLP_USE_BOOST_SUPPORT // STLport 与 Boost 库配合使用

三、安装配置Boost

1.将boost_1_55_0.7z解压至D:\opensource\boost_1_55_0;

2.使用VS2010的命令运行bootstrap.bat生成bjam.exe可执行文件

点击开始—>所有程序--> Microsoft Visual Studio 2010-->VisualStudio tools--> Visual Studio 2010 command prompt  D:\Program Files\Microsoft Visual Studio 10.0\VC> cdD:\opensource\boost_1_55_0

D:\opensource\boost_1_55_0>  booststrap.bat <回车执行>

运行完毕后就可以在bootstrap.bat当期目录看到生成的b2.exebjam.exe;

3.修改user-config.jam文件

user-config.jam文件的位置在boost解压目录[D:\opensource\boost_1_55_0\tools\build\v2]tools\build\v2目录下。打开user-config.jam文件[可用记事本 ],添加以下内容[其它的内容在默认下都是被屏蔽了的 ]:

using msvc : 10.0 : : <compileflags>/wd4819  <compileflags>/D_CRT_SECURE_NO_DEPRECATE  <compileflags>/D_SCL_SECURE_NO_DEPRECATE  <compileflags>/D_SECURE_SCL=0 ;

<compileflags>间用空格隔开,以上的 ':'及‘::’的格式都是正确的。如果开发环境为VS2008则msvc项应为 msvc:9.0。保存后关闭文件。

4.全部编译,将编译的库放在指定的目录,则可以这样子书写bjam命令:

bjam stage --toolset=msvc-10.0 --build-type=complete --stagedir="D:\opensource\boost_1_55_0\bin\vc10" link=static runtime-link=shared threading=multi debug release


三、配置VS2010

    1.VS2010菜单,View,Property Manager,Debug|Win32,双击Microsoft.Cpp.Win32.user,Common Properties,VC++ directories。

在 Include Directories 下添加 D:\opensource\STLport\stlport 。
在 Library Directories 下添加 D:\opensource\STLport\lib 。
    2.VS2010菜单,View,Property Manager,Debug|Win32,双击Microsoft.Cpp.Win32.user,Common Properties,VC++ directories。

在 Include Directories 下添加 D:\opensource\boost_1_55_0\stlport 。
在 Library Directories 下添加 D:\opensource\boost_1_55_0\lib 
四、测试
#include "stdafx.h"
#include <boost/timer.hpp>
#include <iostream>
using namespace std;
using namespace boost;

#define _STLP_USE_STATIC_LIB	// 使用 STLport 静态库
#define _STLP_DEBUG						// STLport 启用 Debug 模式下的检查功能
#define _STLP_USE_BOOST_SUPPORT	// STLport 与 Boost 库配合使用

int _tmain(int argc, _TCHAR* argv[])
{
	timer t;
	cout << "max timespan:" << t.elapsed_max()/3600 << "h" << endl;
	cout << "min timespan:" << t.elapsed_min() <<  "s" << endl;
	cout << "time elapsed:" << t.elapsed() << "s" << endl;
	cout << "Boost is wrong, if there don't print time" << endl;
	system("pause");
	return 0;
}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值