编译 Online Multiclass LPBoost [windows]

      由于科研需要,今天编译了Amir Saffair 的 OMLPBoost 的package(http://www.ymer.org/amir/software/online-multiclass-lpboost/),这个包里面包括了OnlineTree,OnlineRF,OnlineMCBoost, OnlineMCLPBoost, LARANK等几种算法。该包默认的编译运行环境为Linux,但由于各种需求,需要让它在windows环境下运行。于是今天把它在windows VS2008上编译了一下,并且成功运行,着这里对其中遇到的问题和解决方案进行总结。

1.  该程序依赖于两个C++库,分别是libconfig和Eigen2,因此第一步是下载这两个库,并安装配置。

* libconfig: C/C++ Configuration File Library
  http://www.hyperrealm.com/libconfig/
  Version used for this package: 1.4.4

该库用于读取结构性配置文件,如:test.cfg.txt

博主安装的是 libconfig-1.4.9 版本,采用vs 2008 编译通过,没有任何问题。在debug情况下,得到 libconfig++_d.lib


* Eigen2: C++ template library for linear algebra
  http://eigen.tuxfamily.org/index.php?title=Main_Page
  Version used for this package: 2.0.12

该库无须预先编译,只需下载后解压即可。

博主用的是 Eigen 2.0.17 版本

2.  创建OMLPBoost 工程,将tar解压后的文件复制到工程目录下, 并将以下目录加入到工程包含目录


 ..\eigen-eigen-b23437e61a07\eigen-eigen-b23437e61a07

..\libconfig-1.4.9\libconfig-1.4.9\lib


将libconfig++_d.lib所在目录加入到附加库目录,添加附加依赖项 libconfig++_d.lib


3.  解决 “sys/time.h”: No such file or directory 问题。

sys/time.h 为linux下的一个提供time相关支持的文件,但windows并不支持。

因此,博主希望利用windows提供的API来实现time.h的功能,代码可参考:

http://www.refcode.net/2013/02/gettimeofday-for-windows_13.html

创建 systime.h 

#include <windows.h> //I've ommited this line.

#if defined(_MSC_VER) || defined(_MSC_EXTENSIONS)
#define DELTA_EPOCH_IN_MICROSECS  11644473600000000Ui64
#else
#define DELTA_EPOCH_IN_MICROSECS  11644473600000000ULL
#endif
int gettimeofday(struct timeval *tv, struct timezone *tz);
struct timezone 
{
	int  tz_minuteswest; /* minutes W of Greenwich */
	int  tz_dsttime;     /* type of dst correction */
};

创建 systime.cpp

#include "systime.h"

int gettimeofday(struct timeval *tv, struct timezone *tz)
{
	FILETIME ft;
	unsigned __int64 tmpres = 0;
	static int tzflag;

	if (NULL != tv)
	{
		GetSystemTimeAsFileTime(&ft);

		tmpres |= ft.dwHighDateTime;
		tmpres <<= 32;
		tmpres |= ft.dwLowDateTime;

		/*converting file time to unix epoch*/
		tmpres -= DELTA_EPOCH_IN_MICROSECS; 
		tmpres /= 10;  /*convert into microseconds*/
		tv->tv_sec = (long)(tmpres / 1000000UL);
		tv->tv_usec = (long)(tmpres % 1000000UL);
	}

	if (NULL != tz)
	{
		if (!tzflag)
		{
			_tzset();
			tzflag++;
		}
		tz->tz_minuteswest = _timezone / 60;
		tz->tz_dsttime = _daylight;
	}

	return 0;
}
将所有  <sys/time.h> 改为 "systime.h" 。

另外,由于windows中没有 getpid 的实现 

我们将

srand(TV.tv_sec * TV.tv_usec + getpid() + getDevRandom());

改为

srand(TV.tv_sec * TV.tv_usec + getDevRandom());

3. 解决 “ext/hash_map”: No such file or directory 问题,参考http://msdn.microsoft.com/en-us/library/6x7w9f6z.aspx

找到 larank.h 

#include <ext/hash_map>
#include <ext/hash_set>
改为

#include <hash_map>
#include <hash_set>



#define STDEXT_NAMESPACE __gnu_cxx
改为

#define STDEXT_NAMESPACE stdext


4. 添加OMCLPBoost\src\linear_larank 中的三个文件到工程目录:

vectors.cpp

vectors.h

wrapper.h

完成以上几个步骤之后可以对工程编译,此时编译应该没有问题。









  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值