Windows上面编译和简单测试一下leveldb

转:http://gmd20.blog.163.com/blog/static/1684392320131733835919/

已经port到windows 平台了,不过在官网下载的源码包是不能直接编译的
https://code.google.com/p/leveldb/downloads/list

官方的git 里面有windows的分支,不过很遗憾,由于我们伟大的防火墙,git clone不下来。不过看在线的源码,应该里面的源码也是不完整的。
不过那个分支下面有个Windows的编译文档的说明 https://code.google.com/p/leveldb/source/browse/WINDOWS?name=windows



1.  在vc里面创建 动态链接库工程,指定已经存在的目录,直接把leveldb的源文件导入项目里面。
2.  配置 boost 和 leveldb的include目录
3. 添加预定义宏, LEVELDB_PLATFORM_WINDOWS 和 OS_WIN
4.  到官方的 windows 分支,和 这里 http://code.google.com/r/kkowalczyk-leveldb/source/browse/#git%2Fwin 找到下面这些文件,添加到 leveldb的目录和工程里面去。      
    utill/env_win.cc
    util/win_logger.h
    utl/win_logger.cc
    port/port_win.h
    port/port_win.cc

    修改
    port.h  
加上 Windows平台的头文件     port/port_win.h

// Copyright (c) 2011 The LevelDB Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. See the AUTHORS file for names of contributors. #ifndef STORAGE_LEVELDB_PORT_PORT_H_ #define STORAGE_LEVELDB_PORT_PORT_H_ #include <string.h> // Include the appropriate platform specific file below. If you are // porting to a new platform, see "port_example.h" for documentation // of what the new port_<platform>.h file must provide. #if defined(LEVELDB_PLATFORM_POSIX) # include "port/port_posix.h" #elif defined(LEVELDB_PLATFORM_CHROMIUM) # include "port/port_chromium.h" #elif defined(LEVELDB_PLATFORM_WINDOWS) # include "port/port_win.h" #endif #endif // STORAGE_LEVELDB_PORT_PORT_H_

参考 port_posix.h 修改。
port/port_win.h
 port/port_win.cc
加上  InitOnce 的声明和定义

// Thread-safe initialization. // Used as follows: // static port::OnceType init_control = LEVELDB_ONCE_INIT; // static void Initializer() { ... do something ...; } // ... // port::InitOnce(&init_control, &Initializer); typedef long OnceType; #define LEVELDB_ONCE_INIT 0 extern void InitOnce(port::OnceType*, void (*initializer)());

//----------------cpp-----------------------------------

 void InitOnce(OnceType* once, void (*initializer)()) { if (InterlockedCompareExchange (once, 1,0) == 0 ) { initializer(); } }


5.  修复头文件 包含的错误  unistd.h

#ifdef WIN32 #include <io.h> #include <process.h> #else #include <unistd.h> #endif


6. 从项目里面移除所有 xxx_text.c c  xxxx_bench.cc 测试和性能测试相关源文件。
7.在需要导出的类前加__declspec(dllexport)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值