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

Showing 1-5 of 5 messages
How can I compile leveldb as a dll so I can use in my C# program? X Chen 1/18/12 4:03 AM
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
Re: [leveldb] How can I compile leveldb as a dll so I can use in my C# program? Jeremiah Peschka 1/18/12 4:17 AM

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

Re: How can I compile leveldb as a dll so I can use in my C# program? X Chen 1/18/12 4:35 AM
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
Re: How can I compile leveldb as a dll so I can use in my C# program? X Chen 1/18/12 8:10 AM
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
Re: [leveldb] Re: How can I compile leveldb as a dll so I can use in my C# program? Krzysztof Kowalczyk 1/18/12 2:20 PM
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