在windows mobile6下编译通过。
1、建立工程。
新建一个mobile空工程。
加进文件就不多说了,将gloox的头文件、和cpp加进目录。
2、配置工程编译属性。
将下载的gloox目录下的config.h.win拷贝一份到工程目录下(不是解决方案目录,这样做的目的是便于以后随便拷贝这个现成的gloox mobile工程)。
配置config.h.win,mobile平台貌似sasl和tls会有点小问题,所以先不用这两个,先编译通过再说,后续再修改。将ssl和tls都注释掉,剩下的文件内容如下:
/* Comment out if you don't have the `setsockopt' function. Usually available. */
#define HAVE_SETSOCKOPT 1
#ifdef _MSC_VER
#pragma comment( lib, "Dnsapi.lib" )
#pragma comment( lib, "Secur32.lib" )
#pragma comment( lib, "Crypt32.lib" )
//#pragma comment( lib, "ws2_32.lib" )
#pragma comment( lib, "ws2.lib" )
#pragma comment( lib, "winsock.lib" )
/* The following silences a few C4355 warnings ('this' : used in member initializer list).
This is only used with Parser which doesn't do anything with its TagHandler in the ctor,
so muting C4355 is safe. */
#pragma warning( disable : 4355 )
/* The following silcences warnings concerning "unsafe" functions (sprintf, strncpy, etc.).
They are used in a safe way here, though. */
#pragma warning( disable : 4996 )
#endif
改完了以后打开config.h,将config.h.win的目录由“../ config.h.win”改成“config.h.win”
2、设置工程属性。
这个根据需要自己配置一下,现在编译应该不用改也可以编译过,加到其他解决方案的时候可能会有问题,到时候看具体问题再具体改吧。
3、编译。
此时编译仍然会报错。解决如下:
1、/dns.cpp(346) : error C3861: 'getprotobyname': identifier not found
添加# include <winsock2.h>
添加#include <sstream>
2、error C2039: 'time' : is not a member of 'std'
将std::time(0)改为time(0) 去掉std
3、clientbase.cpp(502) : error C2440: '=' : cannot convert from 'unsigned char *' to 'unsigned short *'
4、const std::string ClientBase::getID()中time没实现
改成:
#ifdef _WIN32_WCE
char r[8+1];
sprintf( r, "%08x", rand() );
std::string ret( r, 8 );
return std::string( "uid" ) + ret;
#else
std::ostringstream oss;
oss << ++m_idCount;
return std::string( "uid" ) + oss.str();
#endif
至此,gloox1.0上的mobile版本移植完毕。
可以去下载的gloox文件里找个例子跑一下。调例子的时候因为我们没有设置sasl和tls,所以需要将client的sasl和tls设置为false,才能正确登录。
以后有时间会更新添加sasl和tls的解决方案。