linux leveldb 1.23 编译

yum install cmake
yum install gcc_g++
yum install git llvm
yum install llvm

从github下载leveldb, googletest, benchmark

unzip benchmark-7d0d9061d83b663ce05d9de5da3d5865a3845b79.zip
unzip googletest-662fe38e44900c007eccb65a5d2ea19df7bd520e.zip
tar -xv -f leveldb-1.23.tar.gz
mv googletest-662fe38e44900c007eccb65a5d2ea19df7bd520e googletest
mv benchmark-7d0d9061d83b663ce05d9de5da3d5865a3845b79 benchmark
rm -rf ./leveldb-1.23/third_party/googletest   ./leveldb-1.23/third_party/benchmark
mv benchmark googletest  ./leveldb-1.23/third_party/
cd leveldb-1.23/
cmake CMakeLists.txt

make && make install


vim leveldb_test.cc

#include "leveldb/db.h"
#include 

int main()
{
 // 声明
 leveldb::DB* mydb;
 leveldb::Options myoptions;
 leveldb::Status mystatus;

 // 创建
 myoptions.create_if_missing = true;
 mystatus = leveldb::DB::Open(myoptions, "testdb", &mydb);

 // 写入数据
 std::string key{"penglaiyxy"};
 std::string value{"a handsome man"};
 if (mystatus.ok()) {
    mydb->Put(leveldb::WriteOptions(), key, value);
 }

 // 读取数据
 std::string key_ {"penglaiyxy"};
 std::string val_;
 mydb->Get(leveldb::ReadOptions(), key_, &val_);
 std::cout << key_ << ": " << val_ << std::endl;
}

 g++ leveldb_test.cc -lleveldb -lpthread  -o leveldb_test

[root@leveldbstar penglaiyxy]# ./leveldb_test
penglaiyxy: a handsome man
 

你可能感兴趣的:(linux,big,data)