Leveldb Compile and Use
作者:互联网
先clone下来
git clone --recurse-submodules https://github.com/google/leveldb.git
再Build
mkdir -p build && cd build
cmake -DCMAKE_BUILD_TYPE=Release .. && cmake --build . &&
cd .. &&
sudo cp build/libleveldb.a /usr/local/lib/ &&
sudo cp -r include/leveldb/ /usr/local/include/
把生成的libleveldb.a加到usr/local/lib中
sudo cp build/libleveldb.a /usr/local/lib/
sudo cp -r include/leveldb/ /usr/local/include/
新建demo
#include <cassert>
#include <iostream>
#include <string>
#include <leveldb/db.h>
int main() {
leveldb::DB* db;
leveldb::Options options;
options.create_if_missing = true;
leveldb::Status status = leveldb::DB::Open(options, "/tmp/testdb", &db);
assert(status.ok());
std::string key = "apple";
std::string value = "A";
std::string get;
leveldb::Status s = db->Put(leveldb::WriteOptions(), key, value);
if (s.ok()) s = db->Get(leveldb::ReadOptions(), key, &get);
if (s.ok()) std::cout << "读取到的与(key=" << key << ")对应的(value=" << get << ")" << std::endl;
else std::cout << "读取失败!" << std::endl;
delete db;
return 0;
}
编译
g++ -o demo demo.cc -pthread -lleveldb -std=c++11 -lsnappy
标签:Use,Leveldb,Compile,leveldb,build,&&,include,local,usr 来源: https://www.cnblogs.com/attack204/p/16630273.html