Hello World驱动程序无法正确编译 [英] Hello World driver won't compile correctly

查看:935
本文介绍了Hello World驱动程序无法正确编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始进行驱动程序开发,但是我遵循了在此处在线遇到的一些教程,并且试图将驱动程序编译为简单的.sys文件.

I started out driver development, however I followed some tutorials I met online here and I am trying to compile my driver into a simple .sys file.

代码如下:

#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;
}

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

Rather than compile, I get this very funny error:

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

我迷路了,因为我不知道从其他地方寻求答案.我检查了所有内容,并得到了一个有趣的错误,该错误恰好在Visual Studio的其他版本上正常工作.如果删除警告,则不会担心,它可以很好地编译并且不会向屏幕发送任何错误,为什么会这样?

I am lost as I dont know where else to seek answers from. I have checked and checked all and I get this funny error which happens to work fine on other versions of Visual studio. If I remove the warnings, I don't see it to have a worry, it compiles fine and does not send any errors to my screen, why is this so?

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

I am using Visual studio 2019, what could I apparently be missing ??

PS

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

The warnings I get look like this

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  

推荐答案

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

Looks like an issue with 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)无法识别此属性,并表示未知.

With Visual C++ 2017 version 15.8 (compiler version 19.15.26726.0) a new undocumented Compiler option /d1initall and a new attribute __declspec(no_init_all) got added to the Compiler. Intellisense (VS17 and 19) does not recognize this attribute and says its unknown.

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

The Problem is Intellisense not knowing about the existence of the no_init_all attribute.

此属性在正式的Windows SDK和WDK 10.0.18362.0头文件中使用, 这意味着Intellisense会针对包含以下内容的所有项目显示此错误 Windows套件\ 10 \ Include \ 10.0.18362.0 \ um \ winnt.h(588和1093行)或 Windows套件\ 10 \ Include \ 10.0.18362.0 \ km \ ntddk.h(第7597行).

This attribute is used in the official Windows SDK and WDK 10.0.18362.0 header files, that means Intellisense displays this error for all projects that include Windows Kits\10\Include\10.0.18362.0\um\winnt.h (Line 588 & 1093) or Windows Kits\10\Include\10.0.18362.0\km\ntddk.h (Line 7597).

您还可以通过简单地使用__declspec(no_init_all)属性定义结构来重现错误,

You can also reproduce the Error by simply defining a struct with __declspec(no_init_all) Attribute,

__ declspec(no_init_all)结构A {}; 编译良好,没有任何警告/错误,但Intellisense表示错误.

__declspec(no_init_all) struct A {}; This Compiles fine without any warnings/errors but Intellisense says its wrong.

它已于2019年4月29日修复.

It has been fixed on 29th of April, 2019.

这篇关于Hello World驱动程序无法正确编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆