错误LNK2019:函数DriverEntry中引用的未解析的外部符号__CheckForDebuggerJustMyCode

问题描述 投票:6回答:3

我写了一个Windows 10驱动程序。

以下是代码,实际上代码是docs.microsoft.com的示例。

有谁知道我应该怎么做才能解决这个问题。

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


DRIVER_INITIALIZE DriverEntry;
EVT_WDF_DRIVER_DEVICE_ADD KmdfHelloWorldEvtDeviceAdd;


NTSTATUS
DriverEntry(
    _In_ PDRIVER_OBJECT     DriverObject,
    _In_ PUNICODE_STRING    RegistryPath
)
{
    // NTSTATUS variable to record success or failure
    NTSTATUS status = STATUS_SUCCESS;

    // Allocate the driver configuration object
    WDF_DRIVER_CONFIG config;

    // Print "Hello World" for DriverEntry
    KdPrintEx((DPFLTR_IHVDRIVER_ID, DPFLTR_INFO_LEVEL, "KmdfHelloWorld: DriverEntry\n"));

    // Initialize the driver configuration object to register the
    // entry point for the EvtDeviceAdd callback, KmdfHelloWorldEvtDeviceAdd
    WDF_DRIVER_CONFIG_INIT(&config,
        KmdfHelloWorldEvtDeviceAdd
    );

    // Finally, create the driver object
    status = WdfDriverCreate(DriverObject,
        RegistryPath,
        WDF_NO_OBJECT_ATTRIBUTES,
        &config,
        WDF_NO_HANDLE
    );
    return status;
}


NTSTATUS
KmdfHelloWorldEvtDeviceAdd(
    _In_    WDFDRIVER       Driver,
    _Inout_ PWDFDEVICE_INIT DeviceInit
)
{
    // We're not using the driver object,
    // so we need to mark it as unreferenced
    UNREFERENCED_PARAMETER(Driver);

    NTSTATUS status;

    // Allocate the device object
    WDFDEVICE hDevice;

    // Print "Hello World"
    KdPrintEx((DPFLTR_IHVDRIVER_ID, DPFLTR_INFO_LEVEL, "KmdfHelloWorld: KmdfHelloWorldEvtDeviceAdd\n"));

    // Create the device object
    status = WdfDeviceCreate(&DeviceInit,
        WDF_NO_OBJECT_ATTRIBUTES,
        &hDevice
    );
    return status;
}

救命!如果您有任何建议,请告诉我。

错误消息是:

Driver.obj : error LNK2019: unresolved external symbol __CheckForDebuggerJustMyCode referenced in function DriverEntry
windows driver
3个回答
14
投票

这与Visual Studio 2017 15.8中的新C++ Just My Code Stepping功能有关。

如果出现错误,请打开“项目属性”对话框,并将“配置属性 - > C / C ++ - >常规 - >支持我的代码调试”选项设置为否。


4
投票

这与Visual Studio 2017 15.8中的新C ++ Just My Code Stepping(JMC)功能有关。因为该功能依赖于CRT(C运行时库),如果项目没有链接到CRT,它可能会命中error LNK2019: unresolved external symbol __CheckForDebuggerJustMyCode

解决方法是通过以下方法之一禁用JMC:

  1. 在项目设置中,“配置属性” - >“C / C ++” - >“常规”:“支持我的代码调试”。改为NO。
  2. 在项目设置中,将/JMC-添加到“配置属性” - >“C / C ++” - >“命令行” - >“其他选项”

3
投票

在Visual Studio 15.8中,他们引入了JustMyCode调试,它实际上打破了调试配置中内核驱动程序的编译。

It looks like a bug,但解决方法是现在在发布模式下编译。

© www.soinside.com 2019 - 2024. All rights reserved.