小明思考

          Just a software engineer
          posts - 124, comments - 36, trackbacks - 0, articles - 0
            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

          日歷

          <2012年3月>
          26272829123
          45678910
          11121314151617
          18192021222324
          25262728293031
          1234567

          相冊

          My blogs

          搜索

          •  

          最新評論

          leveldb研究 - 編譯/調試

          Posted on 2012-03-08 11:44 小明 閱讀(4845) 評論(1)  編輯  收藏 所屬分類: 分布式計算
          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 ,這個可選。壓縮還是有必要的吧。
          主站蜘蛛池模板: 青岛市| 吴堡县| 梅州市| 安西县| 来宾市| 龙南县| 富蕴县| 敦化市| 平舆县| 临泽县| 塔城市| 九龙城区| 金华市| 长丰县| 天台县| 南皮县| 嘉定区| 体育| 合阳县| 四会市| 江西省| 湖口县| 伊吾县| 察隅县| 阳谷县| 江达县| 江西省| 万源市| 石城县| 梁平县| 太仆寺旗| 邵阳市| 禄劝| 饶阳县| 长春市| 木兰县| 林口县| 永安市| 凤阳县| 乐昌市| 商水县|