How can I compile leveldb as a dll so I can use in my C# program?

2,014 views
Skip to first unread message

X Chen

unread,
Jan 18, 2012, 7:03:28 AM1/18/12
to leveldb
My program is written in C# and I am not familiar with C++.

I wish to use leveldb, however, I believe there is no good port yet
for C#.

So I think whether I can compile leveldb into dll and use it in my C#
program.

Can I do it? and could anyone pls give me some guide of how to do it?

Thanks

Jeremiah Peschka

unread,
Jan 18, 2012, 7:17:15 AM1/18/12
to lev...@googlegroups.com

Once you complied leveldb for Windows, you should be able to reference the DLL and then use PInvoke to make calls into leveldb. Just as when using any other unmanaged resource, make sure to wrap calls to leveldb with a using() directive and dispose of them properly or else you could run into memory management issues.

Jeremiah Peschka
Founder, Brent Ozar PLF

X Chen

unread,
Jan 18, 2012, 7:35:34 AM1/18/12
to leveldb, jeremiah...@gmail.com
Hello

Do you mind telling me how to compile leveldb for Windows? I followed
the instructions in the doc, but the whole solution gave warning of
uint_32 can't be recognized or something

Thanks

On Jan 18, 12:17 pm, Jeremiah Peschka <jeremiah.pesc...@gmail.com>
wrote:
> Once you complied leveldb for Windows, you should be able to reference the
> DLL and then use PInvoke to make calls into leveldb. Just as when using any
> other unmanaged resource, make sure to wrap calls to leveldb with a using()
> directive and dispose of them properly or else you could run into memory
> management issues.
>
> Jeremiah Peschka
> Founder, Brent Ozar PLF

X Chen

unread,
Jan 18, 2012, 11:10:58 AM1/18/12
to leveldb
I followed the instructions here

http://kkowalczyk-leveldb.googlecode.com/git/WINDOWS

but I got 405 errors, such as "Error 8 error C2065: 'size' :
undeclared identifier", "Error 1 error C2065: 'uint32_t' : undeclared
identifier", etc

Any one can help me with this?

I have included boost libs, and done everything that is told in the
instructions above.

thanks

Krzysztof Kowalczyk

unread,
Jan 18, 2012, 5:20:19 PM1/18/12
to lev...@googlegroups.com
Sorry about lack of documentation in my port. To compile
kkowalczyk-leveldb run build.bat script in win directory.
Alternatively, you can open one of the many Visual Studio 2010 project
files in win directory (they are there to make testing easier).

build.bat will build release and debug version of 32bit and 64bit
version (in rel, dbg, rel64bit, dbg64bit directory). It creates all
test programs (e.g. arena_test.exe, cache_test.exe etc., statically
linked) as well as libleveldb.dll, which can be used from C#, if you
write a wrapper, using C-level apis (see db/c_test.c for how to use
C-level API, c_test.exe for test that exercises it).

Note that if you don't have 64bit compilers installed (they are
optional in Visual Studio 2010), build.bat will fail at some point.
Ignore that - 32 bit versions should have been built (in rel and dbg
directories).

If you want to recreate the build, you can analyze makefile.msvc,
build.bat and build.py to see how the build system works.

The WINDOWS file describes the other windows port, based on boost. My
port doesn't use boost or any other external dependencies and is pure
win32 API based. Most likely what happened is that you tried to
compile env_boost.cc and not env_win.cc.

-- kjk

Ren Z

unread,
Oct 12, 2014, 9:49:40 AM10/12/14
to lev...@googlegroups.com
For those who still struggle with this problem: I've  recently found this:

https://bitbucket.org/robertvazan/leveldb-windows
https://bitbucket.org/robertvazan/leveldb.net

also cloned to github here:

https://github.com/ren85/leveldb.net
https://github.com/ren85/leveldb-windows

Compile leveldb-windows with VS2013, copy resulting dll to leveldb-windows and everything works like a charm.
Reply all
Reply to author
Forward
0 new messages