Neio Notes Share knowledge and experience with you

25Oct/090

First C++ Programming Experience with Hypertable(A)

前言

目前正在为Hypertable做一层封装,使之通过ZeroMQ或RabbitMQ提供一个通用数据访问接口。

说来蛮郁闷的,编译一个Hypertable的example耗费了我一天半的时间。一来,网速慢,下载boost, thrift, log4cpp等库,耗费了很多时间;二来,没有在Linux下做过项目。

下面我以example里面的freebase作为例子,说明编译环境的配。

编译Freebase例子

一、环境

Ubuntu 8.10

hypertable 0.9.2.7  (hypertable-0.9.2.7-linux-i386.deb

二、编译所需库

1. libboost1.40-dev

注意: Ubuntu 8.10上的libboost-dev是1.34的版本,需要另外找1.4的,否则编译的时候会出现 undefined reference to boost::system:: 之类的错误。

可以用一下两种方式解决:

一是找debian的官方源,然后用apt-get install的方式安装:

在sources.list下面添加:

deb http://ftp2.de.debian.org/debian unstable main contrib non-free

然后运行:

sudo apt-get update

sudo apt-get install libboost1.40-all-dev

若出现没有公钥(NO_PUBKEY)的错误,请参考这里解决。

二是下载boost的deb包后安装;

三是从Boost官方网站下载源代码来编译。

2.配置CMakeList.txt

以下是我根据我的环境配置的CMakeList.txt的内容,请读者根据自己的环境调整。

include_directories( ./
/usr/include/boost/
/usr/include/log4cpp/
/usr/local/include
/opt/hypertable/current/include
/usr/include/thrift
)

link_directories(
/opt/hypertable/current/lib/
/usr/local/lib/
/usr/lib/
)

add_executable(freebase_load freebase_load.cc freebase_parser.cc)

target_link_libraries(

freebase_load
libHyperThrift.a
libHypertable.a
libHyperComm.a
libHyperspace.a
libHyperCommon.a
libHyperTools.a
libHyperDfsBroker.a
libHyperDfsCmds.a
libHyperRanger.a
libsigar-x86-linux.so
libdb_cxx-4.6.so
libboost_filesystem.so
libboost_iostreams.so
libboost_program_options.so
libboost_regex.so
libboost_system.so
libboost_signals.so
libboost_thread.so
libboost_date_time.so
libexpat.so
libgcc_s.so
libthrift.so
libthriftnb.so
libstdc++.so
libpthread.so
libz.so
liblog4cpp.so
libtcmalloc_minimal.so
libdl.so
libevent.so
libcurses.so

)

3.为程序编写配置文件

在程序运行目录相对地址(例如:/opt/hyperspace/current/examples/freebase)下,添加conf/hypertable.cfg文件。

往里面添加配置内容,例如我的:

Hypersapce.Master.Host=localhost

Hyperspace.Master.Port=38040

Hyperspace.Master.Dir=hyperspace

Hyperspace.Master.Workers=20

4. 编译运行

首先,在hypertable中添加freebase的数据结构,即create-table-freebase.hql里面的内容。

然后,运行以下几句编译和运行

$sudo cmake ./

$sudo make

$./freebase  aircraft_model.tsv

至此,试验大功告成。接接下去就是开始设计自己的分装了。

No Comments

  • (Required)
  • (Required, will not be published)