1

Building with/ Using VS2010 Platform SDK (Microsoft Windows SDK v7.1) installed.

When i try to build the Sample LSP (located in C:\Program Files\Microsoft Platform SDK\Samples\NetDS\WinSock\LSP)

!--BEGIN RESOLVED--!

I get 16 of the same two errors below.

   Error    1   error C1083: Cannot open include file: 'nt.h': No such file or directory    c:\program files\microsoft sdks\windows\v7.1\samples\netds\winsock\lsp\nonifslsp\lspdef.h   22  1   LSP
   Error    7   error C1083: Cannot open include file: 'lspcommon.h': No such file or directory c:\program files\microsoft sdks\windows\v7.1\samples\netds\winsock\lsp\install\instlsp.h    35  1   LSP

When i added the source code of this sample to VS, i use File>New ProjectFrom Existing Code. Once i do that, VS starts importing all the Platform SDK include files. I was reading elsewhere that not having the includes from PSDK would cause problems, but this doesnt seem to be the case here.

!--END RESOLVED--!

I now run into 3 more errors after fixing the above problem:

Error   1   error LNK2005: "struct _GUID gProviderGuid" (?gProviderGuid@@3U_GUID@@A) already defined in lspguid.obj C:\Program Files\Microsoft SDKs\Windows\v7.1\Samples\netds\winsock\lsp\instlsp.obj  LSP
Error   6   error CVT1100: duplicate resource.  type:MANIFEST, name:1, language:0x0409  C:\Program Files\Microsoft SDKs\Windows\v7.1\Samples\netds\winsock\lsp\CVTRES   LSP
Error   7   error LNK1123: failure during conversion to COFF: file invalid or corrupt   C:\Program Files\Microsoft SDKs\Windows\v7.1\Samples\netds\winsock\lsp\LINK LSP

I have not changed any of the contents/files in the LSP sample.

Currently I'm just trying to build it.

Any insight on this would be helpful.

Thanks.

Gilles 'SO- stop being evil'
  • 104,111
  • 38
  • 209
  • 254
Dacto
  • 2,901
  • 9
  • 45
  • 54

3 Answers3

2

The file lspcommon.h is part of the LSP sample, you should be able to find it in the 'common' subfolder. (C:\Program Files\Microsoft SDKs\Windows\v7.1\Samples\netds\winsock\lsp\common)

If you double click on one of your errors the editor will open focused on the line that's giving problems. Do that for lspdef.h line 22 and you'll see the code looks like this...

#ifndef _PSDK_BLD
#include <nt.h>
#include <ntrtl.h>
#include <nturtl.h>
#endif

That means, the nt.h file (and two others) is only included if the macro _PSDK_BLD is not defined. Look a little lower at line 35 and you'll see the code looks like this...

#ifndef _PSDK_BLD
#include <lspcommon.h>
#else
#include "..\common\lspcommon.h"
#endif

In this case, if the macro is not defined the code includes the file lspcommon.h, but if the macro is defined then the code includes the file lspcommon.h from the common foider.

It seems likely then that your problems are happening because _PSDK_BLD is not defined. From the style of the #ifdef it doesn't look like the macro has to be defined to any specific value, just defined.

In Visual Studio, go to Project Properties, drill down to C/C++ and then Preprocessor. Then find the preprocessor definitions line and click on the value. Now select edit and add _PSDK_BLD to the list of preprocessor definitions.

Watch out for that leading underscore, and remember to make the change for Debug and Release configurations (and for all the platforms you may have defined)


The error LNK2005 means that the linker found two definitions for the object it is trying to link - which is a problem because there's no way for the linker to be able to tell which of the two definitions it should use.

In this particular case, the object the linker is trying to resolve is "struct _GUID gProviderGuid". If you look in the files instlsp.h, lspdef.h (both of them) and lspcommon.h you'll see code that looks like this

extern GUID                 gProviderGuid;

That declares an external variable called gProviderGuid of type GUID (which is a struct). The linker has to resolve that external reference in any file that included one of those header files and then made a reference to gProviderGuid.

From the "already defined in lspguid.obj" part of the error we know the linker has looked inside the file lspguid.obj and found a definition of gProviderGuid. Sure enough, if we look inside lspguid.cpp we can see a definition of gProviderGuid with a value starting 0xc5fabbd0.

From the "C:\Program Files\Microsoft SDKs\Windows\v7.1\Samples\netds\winsock\lsp\instlsp.obj" part of the same error we know that the linker has also looked inside the file instlsp.obj and found a second definition of gProviderGuid. If we look inside intlsp.cpp we can see another definition of gProviderGuid (this time without any value).

The problem then is that the linker is looking in both lspguid.obj and intlsp.obj and finding conflicting definitions of gProviderGuid.

Those two files should not be part of the same build so we shouldn't expect a single run of the linker to read them both at the same time.

The LSP project is made up of four parts: lspcommon which is used to generate the static library lspcommon.lib; ifslsp which is used to generate the file ifslsp.dll; nonifslsp which is used to generate the file nonifslsp.dll and install which is used to generate the file Instlsp.exe. See the readme.txt file in lsp and the makefile files in the various folders for more details.

If you are going to build LSP inside Visual Studio, you really need four different projects in your solution, one each for lspcommon, ifslsp, nonifslsp and install.

Frank Boyne
  • 4,400
  • 23
  • 30
  • I followed your advice and it worked for resolving that problem, now i have run into another 3 errors (added to the main question post.) – Dacto Mar 29 '11 at 02:56
  • This is just a guess but: when you used 'File>New ProjectFrom Existing Code' did you make one big LSP project or did you make separate projects to generate Instlsp.exe, ifslsp.dll and nonifslsp.dll? – Frank Boyne Mar 29 '11 at 17:58
  • You are quite right in assuming i made one big project. Testings now. – Dacto Mar 31 '11 at 00:54
  • I confused on how to add more than one "Project from existing code" to a single solution. – Dacto Mar 31 '11 at 01:35
  • Probably the easiest thing to do is to make four different "Project from existing code" projects/solutions and then tie them together. Start by doing "Project from existing code" separately in each of the ifslsp, nonifslsp, install and common folders. The ifslsp and nonifslsp projects should be DLL, install should be an exe and common should be a Static Library (lib). When you're done creating the common project, right click on the project (in solution explorer) and rename it to be lspcommon so it generates a file called lspcommon.lib. – Frank Boyne Mar 31 '11 at 21:33
  • Now create a fifth empty solution in the LSP folder using File | New Project and using the Other project Types | Visual Studio Solutions | Blank Solution template. Finally, add the four projects you just created into this blank solution by right clicking on the solution and selecting Add | Existing project. – Frank Boyne Mar 31 '11 at 21:37
  • Im still having trouble, i understand what your saying here, but when i create a solution containing of for example: ifslsp then try to build the .dll it errors, furthermore there isnt a dll in the solution folder after creating the project from existing code. What is going on, what am i missing? – Dacto Apr 02 '11 at 00:08
  • You probably need to adjust the project properties in some way. Build Project From Existing Code can do a lot but it can't do everything. What errors are you getting when you build ifslsp.dll? – Frank Boyne Apr 04 '11 at 21:23
  • Is there anyway i can discuss these code issues with you without having to use stackoverflow? – Dacto Apr 19 '11 at 01:29
1

Add this define to your build: _PSDK_BLD It would solve your problem

Andrew Barber
  • 39,603
  • 20
  • 94
  • 123
0

Try changing #include <nt.h> to #include <winnt.h> and see if it builds.

ildjarn
  • 62,044
  • 9
  • 127
  • 211