leveldb 源码编译 vs版本

为什么要windows版本? 因为方便调试跟进 VS的体验真的很不错.

搜索了一段时间才发现GITHUB有windows版本的leveldb

但是使用VS编译也有不少坑

可以下载网络上的其他朋友的版本  也可以新建VS空工程导入代码

git地址 https://github.com/google/leveldb/tree/windows

使用VS新建工程 导入代码

删除posix和test等相关的一些非win环境和测试代码,添加预编译宏.....一系列操作后才成功

 测试代码

#include <cassert>  
#include "leveldb/db.h"  
#include <iostream>
#include <string.h>



int main() {
    
    std::cout << "hello world!" << std::endl;

    leveldb::DB* db;
    leveldb::Options options;
    options.create_if_missing = true;
    leveldb::Status status = leveldb::DB::Open(options, "/tmp/testdb", &db);
    assert(status.ok());
    if (!status.ok()) {
        std::cout << "open db failed
";
        return -1;
    }

    std::string test_key("123"),test_value("456");
    status = db->Put(leveldb::WriteOptions(), test_key, test_value);
    test_value = ("666");
    status = db->Put(leveldb::WriteOptions(), test_key, test_value);
    if (!status.ok() ){
        std::cout << " write db failed
";
        return -1;
    }
    std::string result;
    status = db->Get(leveldb::ReadOptions(), test_key, &result);
    
    return 0;
}

工程文件和代码已经放置进群 QQ群号码见签名

作 者: itdef
欢迎转帖 请保持文本完整并注明出处
技术博客 http://www.cnblogs.com/itdef/
B站算法视频题解
https://space.bilibili.com/18508846
qq 151435887
gitee https://gitee.com/def/
欢迎c c++ 算法爱好者 windows驱动爱好者 服务器程序员沟通交流
如果觉得不错,欢迎点赞,你的鼓励就是我的动力
阿里打赏 微信打赏
原文地址:https://www.cnblogs.com/itdef/p/8645172.html