While writing a small test driver (mainly for experience purposes) from
scratch, the following problem arised: linker cannot find IoCreateSymbolicLink
within ntoskrnl.lib.
I am using MSVC .net and w2k DDK, running on a wxp pro machine and was unable
to generate an executable with 'build' and dirs/sources/makefile files, so I
created a makefile project with Visual Studio and wrote a very simple makefile
and invoked it with "BuildCommand Line: NMake test.mak" in project properties:
-- test.mak
LINK_OPTS = /driver:WDM /out:test.sys /entry:testmain
LINK_LIBS = hal.lib ntoskrnl.lib ntdll.lib wdm.lib
.obj.sys:
link $(LINK_OPTS) $(LINK_LIBS) $*.obj
test.sys : test.obj
test.obj : test.cpp
-- END testdrv.mak
Everything was compiling and linking fine until I tried to use one of the
IoXxx functions in test.cpp. The linker refuses to find the functions in any
.lib provided with w2k DDK (as far as I can tell, IoCreateSymbolicLink is both
in wdm.lib and ntoskrnl.lib). The following 'link test' code compiles fine and
linker gives the following error:
test.obj : error LNK2019: unresolved external symbol
__imp__IoWriteErrorLogEntry referenced in function _testmain
while it compiles and links perfectly if the call to IoWriteErrorLogEntry is
removed from the code.
--test.cpp
#define _X86_
extern "C"
{
#include <ntddk.h>
}
extern "C"
NTSTATUS DriverMain (PDRIVER_OBJECT DrvObj, PUNICODE_STRING RegPath)
{
KeInitializeSpinLock (NULL);
RtlCopyUnicodeString (NULL, NULL);
IoCreateSymbolicLink (NULL, NULL);
return STATUS_SUCCESS;
}
-- END test.cpp
The linker (and compiler) used are the one shipped with Visual Studio, but the
problem remains exactly the same if using compiler and linker of w2k DDK.
I have tried everything I could think trying to solve the problem, but now I
am stuck. Any hint on how to solve it?
Thanks in advance