代码改变世界

VS2010 编译 STLport 5.2.1 With Boost 1.4.7

2011-10-06 14:47  Orin  阅读(903)  评论(0编辑  收藏  举报

配置 STLport 编译选项

      STLport 本身并没有提供 VS2010 的编译配置选项,如果需要使用 VS2010 编译,可以参照这篇文章对源文件进行修改,打开"stlport\stl\_cstdlib.h“ 找到第158行:

1 inline _STLP_LONG_LONG abs(_STLP_LONG_LONG __x) { return __x < 0 ? -__x : __x; }

将其修改为:

1 #if !defined(_STLP_MSVC) || (_STLP_MSVC < 1600)
2 inline _STLP_LONG_LONG abs(_STLP_LONG_LONG __x) { return __x < 0 ? -__x : __x; }
3 #endif

      如果不想手动修改过文件,可以下载文章中提供的文件包覆盖STLport目录里的文件。这时STLport的配置选项里面多了 msvc10 和 msvc10x64 这两个配置选项,使用这两个配置选项即可在 VS2010 的环境下编译STLport。(使用时把 %boostDir% 替换成 Boost 所在目录)

1 configure msvc10 --use-boost %boostDir%      --编译32位的STLport
2 configure msvc10X64 --use-boost %boostDir% --编译64位的STLport

        这样直接编译支持Boost的STLport会报错,需要修改源文件。打开 "stlport\stl\type_traits.h" 找到

1 #ifdef _STLP_USE_BOOST_SUPPORT  
2 # include <stl/boost_type_traits.h>
3 # include <boost/type_traits/add_reference.hpp>
4 # include <boost/type_traits/add_const.hpp>
5 #endif /* _STLP_USE_BOOST_SUPPORT */

修改为 

1 #ifdef _STLP_USE_BOOST_SUPPORT
2 # include <stl/boost_type_traits.h>
3 # include <boost/type_traits/add_reference.hpp>
4 # include <boost/type_traits/add_const.hpp>
5 # include <boost/type_traits/remove_const.hpp> /*新添加此行*/
6 #endif /* _STLP_USE_BOOST_SUPPORT */

这样进行编译就可以顺利通过。

其他编译选项

[-X] 

使用交叉编译,一般不使用此选项.

 

[--with-static-rtl]

表示使用static C/C++ runtime library (libc.lib family,项目属性选择/MT会用到这个产生的lib)

 

[--with-dynamic-rtl]

表示使用dynamic C/C++ runtime library (msvcrt.lib family,项目属性选择/MD会用到这个产生的lib)

使用 STLport

      使用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 库配合使用