环境:
win7, vs2013
源码链接:(Windows版本)
https://github.com/google/leveldb/tree/windows
Kyoto Cabinet
先期准备:
需用到sqlite3、Kyoto Cabinet、boost库支持,安装说明见(boost自行搜索比较简单):
http://blog.youkuaiyun.com/zhangbohh8662/article/details/72676473
http://blog.youkuaiyun.com/zhangbohh8662/article/details/72644372
开始:
1打开vs2013,点文件->新建->从现有代码文件创建新项目,打开 从现有代码文件创建新项目 向导窗口
2要创建什么类型的项目? 选择Visual C++
3项目文件位置 选择源码所在位置leveldb-windows文件夹所在位置
这里源码文件在E:\LIB\leveldb-windows目录中,所以使用的是E:\LIB\leveldb-windows
4项目名称填写 LevelDB
5使用Visual Studio 项目类型选择 静态库(LIB)项目
如果静态库(LIB)项目没有导入成功,可以先选择Windows应用程序项目
6 在设置"调试"配置的设置 中
预处理器定义 填写 LEVELDB_PLATFORM_WINDOWS;OS_WIN
包括搜索路径 填写 E:\LIB\leveldb-windows;E:\LIB\leveldb-windows\include
不填写也可以。后期可以在项目属性中配置
确定后
配置属性->C/C++->常规->附加包含目录
C:\deps\boost_1_57_0;C:\deps\sqlite3;C:\deps\kyotocabinet-1.2.76\kcwin32\include;$(IncludePath)
配置属性->C/C++->常规->预处理器->预处理器定义
LEVELDB_PLATFORM_WINDOWS;OS_WIN
链接器->常规->附加库目录 或者 库管理器->附加库目录
C:\deps\boost_1_57_0\stage\lib
排除文件
手动从项目中排除所有的 *_test.cc 、*_test.c 和*_bench.cc 文件
排除其他平台的文件
port/port_android.cc
port/port_posix.cc
util/env_posix.cc
如果存在其他平台也排除
改源码的地方
1 db\c.cc文件中头文件unistd.h
unistd.h 是 C 和 C++ 程序设计语言中提供对 POSIX 操作系统 API 的访问功能的头文件的名称。是Unix Standard的缩写。
windows下不支持.直接注释即可
2 port\port.h文件中
注明使用的是windows系统
在预编译中增加
#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_ANDROID)
# include "port/port_android.h"
#elif defined(LEVELDB_PLATFORM_WINDOWS)// 新增部分
# include "port/port_win.h"
#endif // STORAGE_LEVELDB_PORT_PORT_H_
#endif
3.db_bench_sqlite3.cc中会报错: error C3861: “snprintf”: 找不到标识符,解决办法在文件中在预编译处加入:
编译生成lib库即可。