leveldb研究 - 编译/调试

http://www.blogjava.net/sandy/archive/2012/03/15/371423.html#371937

leveldb是 google对bigtable的一个简化版的开源实现,很有研究价值。

我的编译环境:ubuntu 32&g++ 4.6

1.安装git并下载代码

sudo apt-get install git-core
git clone https: // code.google.com/p/leveldb/

2. 编译leveldb

cd leveldb
./build_detect_platform
make

为了能够调试,修改Makefile为debug mode(B模式)
OPT ?= -g2

编译后会生成库文件:libleveldb.a

3. 编写测试程序
ldbtest.cpp
#include <iostream>
#include "leveldb/db.h"

using  namespace std;
using  namespace leveldb;

int main() {
    DB *db ;
    Options op;
    op.create_if_missing =  true;
    Status s = DB::Open(op,"/tmp/testdb",&db);

     if(s.ok()){
        cout << "create successfully" << endl;
        s = db->Put(WriteOptions(),"abcd","1234");
         if(s.ok()){
            cout << "put successfully" << endl;
             string value;
            s = db->Get(ReadOptions(),"abcd",&value);
             if(s.ok()){
                cout << "get successfully,value:" << value << endl;
            }
             else{
                cout << "get failed" << endl;
            }
        }
         else{
            cout << "put failed" << endl;
        }
    }
     else{
        cout << "create failed" << endl;
    }
    delete db;
     return 0;
}
注意link的时候需要加上-lpthread.

运行后得到结果:(Eclipse中运行)


评论

# re: leveldb研究 - 编译/调试  回复  更多评论   

2012-03-15 14:47 by  ayanmw
给你补充下: 
编译命令为g++ ldbtest.cpp -o ldbtest -L. -I./include -lpthread -lleveldb 

(工作目录就是leveldb目录中) include下面是leveldb的头文件,-L 搜索library 为了libleveldb.a能够被调用。 

另外,编译的时候 可以将Makefile中说的snappy 压缩 也带上,还有谷歌perfecttools ,这个可选。压缩还是有必要的吧。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值