编译STLport
windows:
使用vs9以上版本编译,需要修改代码_cstdlib.h(158),增加对新版本的支持:
#if !defined(_STLP_MSVC) || (_STLP_MSVC < 1700)
inline _STLP_LONG_LONG abs(_STLP_LONG_LONG __x) { return __x < 0? -__x : __x; }
#endif
configure.bat msvc9
cd build/lib
nmake clean install
linux:
cd stlport/build/lib
make -f gcc.mak
make -f gcc.mak install
编译ProtoBuf
在http://code.google.com/p/protobuf/ 可以下载到 Protocol Buffers 最新版。
在下载的 Protocol Buffers 中找到 README.txt,此文件包含了关于各个平台安装(编译)Protocol Buffers 的信息。
windows:
打开 vsprojects 目录下的 protobuf.sln 文件,编译整个工程(若需要编译 64 位版本,在 MSVC 中增加相应的Solution Platform)
直接运行生成的 tests.exe 和 lite-test.exe 检查所有的测试是否通过
运行extract_includes.bat 可以抽取头文件到一个 include 目录下
使用STLport编译 Protocol Buffers 会出现编译问题,需要修改一下 vcproject/config.h 文件:
#if _MSC_VER < 1310 || _MSC_VER >= 1600
#define HASH_NAMESPACE std
#else
#define HASH_NAMESPACE stdext
#endif
修改为:
// 增加对 STLport 命名空间的支持
#if _MSC_VER < 1310 || _MSC_VER >= 1600 || defined(_STLPORT_VERSION)
#define HASH_NAMESPACE std
#else
#define HASH_NAMESPACE stdext
#endif
// 为 STLport 定义 hash_map 和 hast_set 类名
#if defined(_STLPORT_VERSION)
#define HASH_MAP_CLASS hash_map
#define HASH_SET_CLASS hash_set
#endif
linux:
./autogen.sh
./configure CXXFLAGS="${CXXFLAGS} -I/home/li9chuan/STLport-5.2.1/stlport -lstlport"
make
make check
make install clean
config.h中hashmap的配置由 m4/stl_hash.m4生成。
由于 stlport 中的 template <class _Key> struct hash { }; 不在std::tr1中,自动生成的config.h使用unordered_map 在编译时会找不到这个定义。
在执行make之前,configure同级目录,修改config.h如下内容:
/* the name of <hash_map> */
#define HASH_MAP_CLASS hash_map
/* the location of <unordered_map> or <hash_map> */
#define HASH_MAP_H <hash_map>
/* the namespace of hash_map/hash_set */
#define HASH_NAMESPACE std
/* the name of <hash_set> */
#define HASH_SET_CLASS hash_set
/* the location of <unordered_set> or <hash_set> */
#define HASH_SET_H <hash_set>
编译错误(g++ (Debian 4.4.7-2) 4.4.7): protobuf/compiler/command_line_interface.cc(1562)
for (set<FieldRange>::iterator i = ranges.begin();
修改为:
for (set<FieldRange>::const_iterator i = ranges.begin();