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

RE: newbie linking IoXxx routines problem by pavel_a

pavel_a
Thu Sep 08 05:19:03 CDT 2005

"Reemul" wrote:
>
> 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

May I suggest two things:

1. Use the current DDK - which is "Win2003 SP1" - even for win2000 projects.
It contains build environment for win2000.
Open one of command prompts that the DDK installs, and run
build from there.
The VS.NET compiler and link are not same as in the DDK.

2. Write in old plain C. No C++ please. Be simpler.

Regards,
--PA


Re: newbie linking IoXxx routines problem by Don

Don
Thu Sep 08 05:37:49 CDT 2005

Lets see:

1. You are attempting to create a driver without using BUILD and the
standard build environement. This will break things pretty good.

2. You are brand new to drivers, yet trying to use C++. While many
experienced users use C++, for a first time out this is a good way to mess
things up.

3. You are using an obsolete version of the DDK, another good way to
have problems. Get the latest DDK.

Three strikes, your out.


--
Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting
Remove StopSpam from the email to reply



"Reemul" <reemul@softhome.REMOVE.THIS.net> wrote in message
news:1o10i1do7fqsdumicqf5klavgu5dvtppvq@4ax.com...
>
> 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