_KeInitializeSpinLock@4 already defined Link Error

I am getting this weird error:

Linking Executable - i386\sysproc.sys
1>errors in directory c:\work\driver\wininternals\timer
1>c:\work\driver\wininternals\timer\ntoskrnl.lib(ntoskrnl.exe) : error LNK2005:xxxxx@4 already defined in driver.obj
1>c:\work\driver\wininternals\timer\i386\sysproc.sys : error LNK1169: one or more multiply defined symbols found

The cause is that I have 2 .cpp files each calling KeInitializeSpinLock() but one includes <wdm.h> while the other includes <ntddk.h>.

How do I resolve the issue aparting from replacing all <wdm.h> includes to <ntddk.h>?</ntddk.h></wdm.h></ntddk.h></wdm.h>

You should only use ntoskrnl.lib from the WDK library directory set by the build environment. DO NOT copy it to your build directory.

No, I didn’t do anything unusual. I just compile my code using a fresh installation of WDK 7.1. I heard that the error is related to a bug in the WDK

It is not a bug. The definition changed from an export to an inline sometime after WDM 1.0. Find the definition of the API in both headers, one of them has an ifdef check to revert back to the export, something like USE_WIN9X_SPINLOCK. Define that and rebuild

Sent from Outlook Mailhttp: for Windows 10 phone

From: xxxxx@hotmail.com
Sent: Saturday, November 28, 2015 10:34 PM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] xxxxx@4 already defined Link Error

No, I didn’t do anything unusual. I just compile my code using a fresh installation of WDK 7.1. I heard that the error is related to a bug in the WDK


NTDEV is sponsored by OSR

Visit the list at: https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.osronline.com%2Fshowlists.cfm%3Flist%3Dntdev&amp;data=01|01|Doron.Holan%40microsoft.com|aadd671bafa74fd9af4d08d2f8871ac4|72f988bf86f141af91ab2d7cd011db47|1&amp;sdata=9ZhA1QIjUI4ahxwRPpeRtR%2BM8DRJLvdY8pt3Gfp3%2BkA%3D

OSR is HIRING!! See https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.osr.com%2Fcareers&amp;data=01|01|Doron.Holan%40microsoft.com|aadd671bafa74fd9af4d08d2f8871ac4|72f988bf86f141af91ab2d7cd011db47|1&amp;sdata=mhq%2Fo1fmxLMWpYDf%2Brwgy9jGZdjzO7uo86M2KKRjttQ%3D

For our schedule of WDF, WDM, debugging and other seminars visit:
https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.osr.com%2Fseminars&amp;data=01|01|Doron.Holan%40microsoft.com|aadd671bafa74fd9af4d08d2f8871ac4|72f988bf86f141af91ab2d7cd011db47|1&amp;sdata=HFY3lgvjqQ6Brm3raD%2FxUZOdpq1IUjm07ZmX1%2FGg%2FIM%3D

To unsubscribe, visit the List Server section of OSR Online at https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.osronline.com%2Fpage.cfm%3Fname%3DListServer&amp;data=01|01|Doron.Holan%40microsoft.com|aadd671bafa74fd9af4d08d2f8871ac4|72f988bf86f141af91ab2d7cd011db47|1&amp;sdata=mni9haErPOyzW0JmEG73VSFuD8BdxXw4PTs7tiHh%2FDc%3D</http:>

>No, I didn’t do anything unusual

Do delete c:\work\driver\wininternals\timer\ntoskrnl.lib. This is “unusual”.