lnk2019 error - time and memory functions, which library?

Hi Guys,

I have a feeling this is a stupid mistake I am making on this driver, but I can’t find it and am hoping someone might have an idea.

I am finishing up a USB network driver and am having some issues linking it. I am obviously missing the right library to link to, but haven’t been able to find the right now. Any ideas? I am building for XP using the DDK for Server 2003.

My sources files is as follows:

TARGETNAME=myDriver

TARGETTYPE=DRIVER

DDKROOT=$(BASEDIR)

INCLUDES= $(DDK_INC_PATH); \
…\inc;

System and NDIS wrapper definitions.

C_DEFINES=-DNDIS_MINIPORT_DRIVER=1 -DNDIS_WDM=1

The driver is built in the XP or .NET build environment

So let us build NDIS 5.1 version.

C_DEFINES=$(C_DEFINES) -DNDIS50_MINIPORT=1 -DWMI_SUPPORT

TARGETLIBS=$(DDK_LIB_PATH)\ndis.lib \
$(DDK_LIB_PATH)\usbd.lib

KMDF_VERSION_MAJOR=1

NO_BINPLACE=1

SOURCES= \
wifimac.cpp \
hw_card.cpp \

Card.cpp

These are the link errors I am getting:

1>ntoskrnl.lib(ntoskrnl.exe) : error LNK2005: xxxxx@4 already defined in wdmutils.obj
1>hw_card.obj : error LNK2019: unresolved external symbol __imp__realloc referenced in function “int __stdcall cbQueryInformation(void *,unsigned long,void *,unsigned long,unsigned long *,unsigned long *)” (?cbQueryInformation@@YGHPAXK0KPAK1@Z)
1>mac_mgmt.obj : error LNK2001: unresolved external symbol __imp__realloc
1>mac_tkip.obj : error LNK2001: unresolved external symbol “unsigned long __stdcall GetTickCount(void)” (?GetTickCount@@YGKXZ)
1>hw_driver.obj : error LNK2019: unresolved external symbol __imp__sscanf referenced in function “void __stdcall GetKey(void *,struct _UNICODE_STRING,int)” (?GetKey@@YGXPAXU_UNICODE_STRING@@H@Z)
1>mac_buf.obj : error LNK2019: unresolved external symbol __imp__malloc referenced in function “unsigned char __stdcall InitBuffers(void)” (?InitBuffers@@YGEXZ)
1>cardwiwave.obj : error LNK2001: unresolved external symbol __imp__malloc
1>mac_buf.obj : error LNK2019: unresolved external symbol __imp__free referenced in function “void __stdcall ReleaseBuffers(void)” (?ReleaseBuffers@@YGXXZ)
1>wdmutils.obj : error LNK2001: unresolved external symbol __imp__free

Any help would be hugely appreciated. If you need any more information, please let me know. Thanks, Val

I’m not sure how, but you’re linking with both wdm.lib & ntoskrnl.lib.

The other problem is that you seem to be using malloc()/free(). You don’t use these in a kernel driver. See ExAllocatePoolWithTag().

Good luck,

mm

Finishing? Doubts, too many problems. As Martin said malloc/free. I’m
adding GetTickCount() which is Win32 function not available in kernel.
It seems as you’re compiling some user mode code to kernel driver which
is wrong.

Next problems:

  • sscanf – bad even in user mode.
  • C++ – asking for problems in kernel unless you exactly know what
    you’re doing
  • incorrect use of C functions in C++ code: GetTickCount@@YGKXZ which
    indicates above point isn’t fulfiled (seems you include user mode
    headers)

BTW, what is USB network driver?

Best regards,

Michal Vodicka
UPEK, Inc.
[xxxxx@upek.com, http://www.upek.com]

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
xxxxx@aol.com
Sent: Tuesday, November 10, 2009 11:20 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] lnk2019 error - time and memory functions,
which library?

Hi Guys,

I have a feeling this is a stupid mistake I am making on this
driver, but I can’t find it and am hoping someone might have an idea.

I am finishing up a USB network driver and am having some
issues linking it. I am obviously missing the right library
to link to, but haven’t been able to find the right now. Any
ideas? I am building for XP using the DDK for Server 2003.

My sources files is as follows:

TARGETNAME=myDriver

TARGETTYPE=DRIVER

DDKROOT=$(BASEDIR)

INCLUDES= $(DDK_INC_PATH); \
…\inc;

System and NDIS wrapper definitions.

C_DEFINES=-DNDIS_MINIPORT_DRIVER=1 -DNDIS_WDM=1

The driver is built in the XP or .NET build environment

So let us build NDIS 5.1 version.

C_DEFINES=$(C_DEFINES) -DNDIS50_MINIPORT=1 -DWMI_SUPPORT

TARGETLIBS=$(DDK_LIB_PATH)\ndis.lib \
$(DDK_LIB_PATH)\usbd.lib

KMDF_VERSION_MAJOR=1

NO_BINPLACE=1

SOURCES= \
wifimac.cpp \
hw_card.cpp \

Card.cpp

These are the link errors I am getting:

1>ntoskrnl.lib(ntoskrnl.exe) : error LNK2005:
xxxxx@4 already defined in wdmutils.obj
1>hw_card.obj : error LNK2019: unresolved external symbol
__imp__realloc referenced in function “int __stdcall
cbQueryInformation(void *,unsigned long,void *,unsigned
long,unsigned long *,unsigned long *)”
(?cbQueryInformation@@YGHPAXK0KPAK1@Z)
1>mac_mgmt.obj : error LNK2001: unresolved external symbol
__imp__realloc
1>mac_tkip.obj : error LNK2001: unresolved external symbol
“unsigned long __stdcall GetTickCount(void)” (?GetTickCount@@YGKXZ)
1>hw_driver.obj : error LNK2019: unresolved external symbol
__imp__sscanf referenced in function “void __stdcall
GetKey(void *,struct _UNICODE_STRING,int)”
(?GetKey@@YGXPAXU_UNICODE_STRING@@H@Z)
1>mac_buf.obj : error LNK2019: unresolved external symbol
__imp__malloc referenced in function “unsigned char __stdcall
InitBuffers(void)” (?InitBuffers@@YGEXZ)
1>cardwiwave.obj : error LNK2001: unresolved external symbol
__imp__malloc
1>mac_buf.obj : error LNK2019: unresolved external symbol
__imp__free referenced in function “void __stdcall
ReleaseBuffers(void)” (?ReleaseBuffers@@YGXXZ)
1>wdmutils.obj : error LNK2001: unresolved external symbol __imp__free

Any help would be hugely appreciated. If you need any more
information, please let me know. Thanks, Val


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online
at http://www.osronline.com/page.cfm?name=ListServer

Thanks mm, hugely appreciate the constructive feedback.

Glad I could help.

Good luck,

mm

Michal Vodicka wrote:

BTW, what is USB network driver?

An NDIS miniport with a USB lower edge?