构建 Microsoft 的 LSP 示例代码
使用 VS2010 构建 已安装平台 SDK(Microsoft Windows SDK v7.1)。
当我尝试构建示例 LSP(位于 C:\Program Files\Microsoft Platform SDK\Samples\NetDS\WinSock\LSP)时
!--开始解决--!
我收到下面 16 个相同的两个错误。
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
当我将此示例的源代码添加到 VS 时,我使用 File>New ProjectFrom Existing Code。 一旦我这样做,VS 就会开始导入所有 Platform SDK 包含文件。我在其他地方读到,没有 PSDK 的包含会导致问题,但这里的情况似乎并非如此。
!--解决完毕--!
修复上述问题后,我现在又遇到了 3 个错误:
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
我没有更改 LSP 示例中的任何内容/文件。
目前我只是想构建它。
对此的任何见解都会有所帮助。
谢谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
文件 lspcommon.h 是 LSP 示例的一部分,您应该能够在“common”子文件夹中找到它。 (C:\Program Files\Microsoft SDKs\Windows\v7.1\Samples\netds\winsock\lsp\common)
如果双击错误之一,编辑器将打开,重点关注出现问题的行。对 lspdef.h 第 22 行执行此操作,您将看到代码如下所示...
这意味着,仅当未定义宏 _PSDK_BLD 时才包含 nt.h 文件(以及其他两个文件)。再往下看第 35 行,您会看到代码如下所示...
在这种情况下,如果未定义宏,则代码包含文件 lspcommon.h,但如果宏是 定义后,代码包含来自 common foider 的文件 lspcommon.h。
那么您的问题很可能是因为未定义 _PSDK_BLD 而发生的。从 #ifdef 的风格来看,宏不需要定义为任何特定值,只需定义即可。
在 Visual Studio 中,转到“项目属性”,向下钻取到“C/C++”,然后转到“预处理器”。然后找到预处理器定义行并单击该值。现在选择编辑并将 _PSDK_BLD 添加到预处理器定义列表中。
请注意该前导下划线,并记住对“调试”和“发布”配置(以及您可能定义的所有平台)进行更改
错误 LNK2005 意味着链接器找到了它尝试链接的对象的两个定义 - 这是一个问题,因为没有办法链接器能够知道它应该使用两个定义中的哪一个。
在这种特殊情况下,链接器尝试解析的对象是“struct _GUID gProviderGuid”。如果您查看文件 instlsp.h、lspdef.h(两者)和 lspcommon.h,您将看到如下所示的代码,
它声明了一个名为 gProviderGuid 的 GUID 类型(这是一个结构体)的外部变量。链接器必须解析包含这些头文件之一的任何文件中的外部引用,然后引用 gProviderGuid。
从错误的“lspguid.obj 中已定义”部分我们知道链接器已查看文件 lspguid.obj 并找到 gProviderGuid 的定义。果然,如果我们查看 lspguid.cpp 内部,我们可以看到 gProviderGuid 的定义,其值从 0xc5fabbd0 开始。
从同一错误的“C:\Program Files\Microsoft SDKs\Windows\v7.1\Samples\netds\winsock\lsp\instlsp.obj”部分我们知道链接器还查看了文件 instlsp.obj 并找到了 gProviderGuid 的第二个定义。如果我们查看 intlsp.cpp 内部,我们可以看到 gProviderGuid 的另一个定义(这次没有任何值)。
那么问题是链接器正在查找 lspguid.obj 和 intlsp.obj 并找到 gProviderGuid 的冲突定义。
这两个文件不应该是同一构建的一部分,因此我们不应该期望链接器的单次运行能够同时读取它们。
LSP项目由四部分组成: lspcommon,用于生成静态库lspcommon.lib; ifslsp,用于生成文件ifslsp.dll; nonifslsp 用于生成文件nonifslsp.dll,install 用于生成文件Instlsp.exe。有关更多详细信息,请参阅 lsp 中的 readme.txt 文件和各个文件夹中的 makefile 文件。
如果要在 Visual Studio 中构建 LSP,则解决方案中确实需要四个不同的项目,每个项目分别用于 lspcommon、ifslsp、nonifslsp 和 install。
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...
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...
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
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.
将此定义添加到您的构建中:_PSDK_BLD
它会解决你的问题
Add this define to your build: _PSDK_BLD
It would solve your problem
尝试将
#include
更改为#include
并查看它是否可以构建。Try changing
#include <nt.h>
to#include <winnt.h>
and see if it builds.