1

I've trying to build lmdb using Visual Studio, but get the following error:

mdb.obj : error LNK2001: unresolved external symbol _NtMapViewOfSection@40
mdb.obj : error LNK2001: unresolved external symbol _NtClose@4
mdb.obj : error LNK2001: unresolved external symbol _NtCreateSection@28

To the first usage of this functions in code there is a following comment:

/* We use native NT APIs to setup the memory map, so that we can
 * let the DB file grow incrementally instead of always preallocating
 * the full size. These APIs are defined in <wdm.h> and <ntifs.h>
 * but those headers are meant for driver-level development and
 * conflict with the regular user-level headers, so we explicitly
 * declare them here. Using these APIs also means we must link to
 * ntdll.dll, which is not linked by default in user code.
 */
NTSTATUS WINAPI
NtCreateSection(OUT PHANDLE sh, IN ACCESS_MASK acc,
  IN void * oa OPTIONAL,
  IN PLARGE_INTEGER ms OPTIONAL,
  IN ULONG pp, IN ULONG aa, IN HANDLE fh OPTIONAL);

How I need to link ntdll.dll in Visual Studio? I understand, that question is stupid, but I can't find solution within a few hours..

Artem Mostyaev
  • 3,874
  • 10
  • 53
  • 60
  • You got your lmdb sources from the trunk, right? I did not try to build it yet but I had no problems with building the 0.9.17 release on Windows. May be you'd better try to build it first? – datjko Dec 04 '15 at 03:51
  • Regarding linking with ntdll I believe you may want to try the Method 1 from http://stackoverflow.com/a/15117763/1027013 – datjko Dec 04 '15 at 03:59
  • Thank you, datjko. I've downloaded sources from github yesterday, but it is 0.9.16 version. Temporally I solved a problem with ntdll.dll with dynamic linking, Method 1 is too complex for me. – Artem Mostyaev Dec 04 '15 at 08:01
  • 2
    I believe the version number in trunk was not updated by mistake. Version 0.9.17 was released in Nov 30, 2015 and is available here https://github.com/LMDB/lmdb/releases/tag/LMDB_0.9.17. As far as I can see, using of functions from ntdll was added to trunk after the release in https://github.com/LMDB/lmdb/commit/fb5a768a77ca5330e15a3a34ceb694bc11cb216a also in Nov 30, 2015. So, unless you want to testdrive the recent development version I believe you'd better use a recent stable version. – datjko Dec 04 '15 at 18:05
  • Great thanks for the right link to the 0.9.17 version! It compiles without problems, because Nt functions were not added into that. It looks like, that functionality is not completed, so it is better to use last stable version, thank you! – Artem Mostyaev Dec 07 '15 at 07:30

2 Answers2

3

You could link with ntdll.lib in Visual Studio.

call me Steve
  • 1,709
  • 3
  • 18
  • 31
0

Great thanks to @datjko! He was right:

I believe the version number in trunk was not updated by mistake. Version 0.9.17 was released in Nov 30, 2015 and is available here github.com/LMDB/lmdb/releases/tag/LMDB_0.9.17. As far as I can see, using of functions from ntdll was added to trunk after the release in github.com/LMDB/lmdb/commit/… also in Nov 30, 2015. So, unless you want to testdrive the recent development version I believe you'd better use a recent stable version.

The problem was solved after following his recommendations.

Artem Mostyaev
  • 3,874
  • 10
  • 53
  • 60