【问题标题】:Hello World driver won't compile correctlyHello World 驱动程序无法正确编译
【发布时间】:2019-10-05 22:41:18
【问题描述】:

我开始开发驱动程序,但是我遵循了一些我在网上遇到的教程,我正在尝试将我的驱动程序编译成一个简单的 .sys 文件。

代码如下所示:

#include <ntddk.h>
#include <wdf.h>

#define UNREFERENCED_PARAMETER(P) (P)
VOID DriverUnload(PDRIVER_OBJECT driver)
{
    DbgPrint("first:HelloWorld End!");
}

NTSTATUS DriverEntry(PDRIVER_OBJECT pDriverObject, PUNICODE_STRING pUnicodeString)
{
    DbgPrint("first:HelloWorld Begin!");
    pDriverObject->DriverUnload = DriverUnload;
    return STATUS_SUCCESS;
}

我得到了这个非常有趣的错误,而不是编译:

Error   C2220   warning treated as error - no 'object' file generated   MyHelloWorldDriver  C:\Users\****\source\repos\MyHelloWorldDriver\MyHelloWorldDriver\main.c 7   

我迷路了,因为我不知道从哪里寻找答案。我已经检查并检查了所有内容,我得到了这个有趣的错误,它恰好在其他版本的 Visual Studio 上运行良好。如果我删除警告,我不觉得它有担心,它编译良好并且不会向我的屏幕发送任何错误,为什么会这样?

我正在使用 Visual Studio 2019,我显然缺少什么??

PS

我收到的警告看起来像这样

Error (active)  E1097   unknown attribute "no_init_all" MyHelloWorldDriver  C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\km\ntddk.h  372 
Error (active)  E1097   unknown attribute "no_init_all" MyHelloWorldDriver  C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\km\ntddk.h  1093    
Warning MSB8038 Spectre mitigation is enabled but Spectre mitigated libraries are not found.  Verify that the Visual Studio Workload includes the Spectre mitigated libraries.  See https://aka.ms/Ofhn4c for more information. MyHelloWorldDriver  C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Microsoft\VC\v160\Microsoft.CppBuild.targets 422 
Error   C2220   warning treated as error - no 'object' file generated   MyHelloWorldDriver  C:\Users\***\source\repos\MyHelloWorldDriver\MyHelloWorldDriver\main.c  7   
Warning C4566   character represented by universal-character-name '\uFF01' cannot be represented in the current code page (1252)    MyHelloWorldDriver  C:\Users\***\source\repos\MyHelloWorldDriver\MyHelloWorldDriver\main.c  7   
Warning C4100   'driver': unreferenced formal parameter MyHelloWorldDriver  C:\Users\***\source\repos\MyHelloWorldDriver\MyHelloWorldDriver\main.c  5   
Warning C4566   character represented by universal-character-name '\uFF01' cannot be represented in the current code page (1252)    MyHelloWorldDriver  C:\Users\***\source\repos\MyHelloWorldDriver\MyHelloWorldDriver\main.c  12  
Warning C4100   'pUnicodeString': unreferenced formal parameter MyHelloWorldDriver  C:\Users\***\source\repos\MyHelloWorldDriver\MyHelloWorldDriver\main.c  10  

【问题讨论】:

  • 警告是什么?
  • @YoYoYonnY 我已经更新了问题,请参阅那里的警告
  • 字符与 ! 不同。
  • 消息看起来很清楚。他们到底有什么问题?
  • 您是否尝试过阅读警告消息并分析他们说什么?分享您的分析。

标签: c visual-studio driver visual-studio-2019


【解决方案1】:

看起来像 Visual Studio 的问题: https://developercommunity.visualstudio.com/content/problem/549389/intellisense-error-e1097-because-intellisense-does.html

这是该链接的副本:

使用 Visual C++ 2017 版本 15.8(编译器版本 19.15.26726.0)新的未记录编译器选项 /d1initall 和 新属性 __declspec(no_init_all) 已添加到编译器。 Intellisense(VS17 和 19)无法识别此属性并表示其未知。

问题是 Intellisense 不知道 no_init_all 属性的存在。

该属性在官方Windows SDK和WDK 10.0.18362.0头文件中使用, 这意味着 Intellisense 会为所有项目显示此错误,包括 Windows Kits\10\Include\10.0.18362.0\um\winnt.h(第 588 和 1093 行)或 Windows Kits\10\Include\10.0.18362.0\km\ntddk.h(第 7597 行)。

您也可以通过简单地定义具有 __declspec(no_init_all) 属性的结构来重现错误,

__declspec(no_init_all) 结构 A {}; 这编译得很好,没有任何警告/错误,但 Intellisense 说它是错误的。


已于 2019 年 4 月 29 日修复。

【讨论】:

  • 您能提供更多信息吗?如果上述链接不再有效会怎样?
  • 您好,您能澄清一下您所说的“已修复”是什么意思吗?我已经将 VS2017 更新到今天的最新版本,但我仍然遇到这个问题。
  • 我也有这个问题,我是最新的。有办法解决吗?
【解决方案2】:

您可以在 Tools/option/Text-Editor/C C++/Extension 中激活预编译头文件并将 Disable Automatic Precompiled Header 设置为 false。

【讨论】:

    【解决方案3】:

    一种可能的解决方法是将此代码添加到主头文件之一:

    #if (_MSC_VER >= 1915)
    #define no_init_all deprecated
    #endif
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-04-25
      • 1970-01-01
      • 2017-01-02
      • 1970-01-01
      • 2014-11-29
      • 1970-01-01
      • 2020-08-02
      • 1970-01-01
      相关资源
      最近更新 更多