-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathInstructions.txt
111 lines (63 loc) · 5.28 KB
/
Instructions.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
The goal of this port is to allow for a full build of the db with as little modification to the source as possible, allowing to quickly deploy LevelDB updates.
The port comes with 2 packages:
a msvc11_port folder holding all the ported code:
the mman port comes from: https://code.google.com/p/mman-win32/
the dirent port is the courtesy of Kevlin Henney
pthread port is largely inspired from locklessinc.com, besides the WinXP compatible port of pthread_cond and pthread_once (http://locklessinc.com/articles/pthreads_on_windows/)
rest is from me besides snprint_C99, found on stackexchange, although it feels overkill (http://stackoverflow.com/questions/2915672/snprintf-and-visual-studio-2010).
I try to explain the why and hows of my code in comments. Ports I've taken from others are more or less commented. All questions regarding these should be directed to their respective authors.
How to build this project, from a fresh project and leveldb's source:
#1 Add all the files found in the following folders to your project:
leveldb/port
leveldb/util
leveldb/table
leveldb/db
(from the leveldb source)
#2 After adding these files, remove from your project all .cc files with _test and _bench suffixes (any file with a main() declared, we're trying to build a library here). Get rid of anything that doesn't end with .cc or .h as well (README's and friends)
#3 add the following folders to your include paths:
/leveldb_windows_port/win32_posix
/leveldb (the leveldb source folder)
/leveldb/include
#4 define following global compiler directives (in project>properties>pconfiguration properties>C/C++>preprocessor):
_CRT_SECURE_NO_wARNINGS
LEVELDB_PLATFORM_POSIX
LEVELDB_CSTDATOMIC_PRESENT
NOMINMAX
USE_CONDVAR
#5 in atomic_pointer.h, look for these lines:
#ifdef LEVELDB_CSTDATOMIC_PRESENT
#include <cstdatomic>
#endif
Replace them with
#ifdef LEVELDB_CSTDATOMIC_PRESENT
#ifdef _WIN32
#include <atomic>
#elif
#include <cstdatomic>
#endif
#endif
#6 in port_posix.h, add these lines after #include <endian.h> #endif:
#ifdef _MSC_VER
#include <win32_posix.h>
#endif
#7 add this line after the includes in c.cc
#define strdup _strdup
#8 add win32_posix.cpp, mman.cpp and dirent_win32.cpp to the project, found in the msvc11_port folder
#9 at this point you can build your project. You are now in front of a few choices, found in Properties > C/C++ > General -> Configuration Type:
exe: you can add one of _test or _bench files back in to build an exe and test the db. I personally ran the benchmark and tests in db_test.cc in 32bit and 64bit to make sure the port was functional.
static lib: This is your best choice. At this point you can simply build the lib and link it to your project. Keep in mind that with static libraries, the runtime library option you pick in your project has to match the one picked to build the lib. This option is found in Properties > C/C++ > Code Generation -> Runtime Library.
2 choices are available: multi threaded (/MT) or multithreaded dll (/MD) (debug versions are meaningless at this point). If your lib was built with /MD, whatever project you're linking it to has to be built with /MD as well, same with /MT.
dynamic lib (dll): This is a decent option however it's one that requires some editing the leveldb source: you'll have to prepend LEVELDB_EXPORT to all the classes and members you want in your dll, or they simply won't be exported.
How to figure out what you need? When you build your .exe, if the linker complains about unresolved external, there you have it. Go back to the leveldb source, look for the symbol with the search function. Once you've found one, right click it and pick "Go To Definition". Add LEVELDB_EXPORT in front of it.
Note: for classes and structs, you have to add LEVELDB_EXPORTS between class/struct and the declaration, like this:
'class myClass' becomes
'class LEVELDB_EXPORT myClass'
Once you're done with that, add LEVELDB_DLL to global definitions in the leveldb project and DLL_BUILD into whatever project you're going to use this dll in.
There's a workaround to this mess, with a .def file, but it's even more miserable: you have to write decorated names of the symbols you want in a .def file and feed it to the linker. Long story short, I have to setup an automated prebuild process to do it programatically, and that's too much work right now xD.
/*** where's snappy at? ***/
If you want to use snappy with leveldb, simply build it from source. Snappy doesn't use any system call so there's nothing else to do but to build it in msvc. You have a couple ways to do this: Either add snappy's code to your leveldb project and build everything on the go (you get some type redefinition bitching though) or, the way I recommend, is to build it as a static lib and link it to your leveldb project.
Building it is straight forward: pick all files .cc and .h files in the snappy source folder, minues the ones ending in _test, pick static lib in the output, make sure it's the right CRT option (/MT or /MD) and proper architecture (x86 or x64), then just build it.
You can grab snappy here: https://code.google.com/p/snappy/downloads/list
/*** my shit won't work on WinXP! ***/
Use the msvc9 project!
Have questions? Need help? Or just want to comment? Pm goatpig on the bitcoin forums (bitcointalk.org), or at [email protected]