VS2017编译LevelDB

环境:

    操作系统:Win7 x64

    编译器:VS2017

   需要Boost库支持,需要先将Boost库编译成为64位版本。

一、项目文件导入

1. 下载leveldb-windows,https://codeload.github.com/google/leveldb/zip/windows

2. 打开VS2017  File->New->Project From Existing Code

   项目创建类型选择:Visual C++

3. Project file location: 选择leveldb-windows源码所在文件夹。D:ProjecTrialVCleveldb-windows

   Project name: 填写LevelDB。

4. Use Visula Studio -> Project tyep:

    选择Windows application project。   

 5. 其他暂时不填写。以后可以在项目属性中再配置。

二、项目配置

项目建成后,Project->Property ,在x64位下属性,配置如下:

1. Configuration Properties->General->Configuration Type   配置成Static library (.lib)

2. C/C++ ->Preprocessor->Preprocessor Definitions

  添加预处理器定义:LEVELDB_PLATFORM_WINDOWS;OS_WIN

3. C/C++ ->General-> Additional Include Directories  添加用到boost头文件目录和leveldb-windows 文件目录。

    D:ProgramFilesoostlibincludeoost-1_65_1

    D:ProjecTrialVCleveldb-windows

    D:ProjecTrialVCleveldb-windowsinclude

4. Linker->General->Additional library Directories  附加boost库

    D:ProgramFilesoostliblib

三、项目文件整理

  1.手动从项目中排除所有的 *_test.cc 和*_bench.cc 文件;(在需要排除的文件右键Exclude From project)

     排除其他平台的文件
     port/port_android.cc
     port/port_posix.cc
     util/env_posix.cc
     如果存在其他平台也排除

    排除文件:

    env_posix.cc

    env_boost.cc

    db_bench_sqlite3.cc

    db_bench_tree_db.cc

    c_test.c

2.  修改port/port.h文件,在第18行处新增加

   #elif defined(LEVELDB_PLATFORM_WINDOWS) 
   #  include "port/port_win.h"  

#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

 3. 修改db/c.cc文件,在第8行处,注释掉#include <unistd.h>

     unistd.h 是 C 和 C++ 程序设计语言中提供对 POSIX 操作系统 API 的访问功能的头文件的名称。是Unix Standard的缩写。
     windows下不支持.直接注释即可

  4. 修改port/port_win.h文件,第34行处,注释掉#define snprintf _snprintf。因为VS2017中已经实现了snprintf的定义,所以不需要这个了。

  四、编译生成LevelDB.lib。

  

原文地址:https://www.cnblogs.com/ike_li/p/8267341.html