Joe Xu
Joe Xu

Reputation: 93

error LNK2019: unresolved external symbol __CheckForDebuggerJustMyCode referenced in function DriverEntry

I write a windows 10 driver.

following is the code, actually the code is a sample of learn.microsoft.com.

is there anyone know what shold i do to deal with this issue.

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

Help! if you have some suggestion, please let me know.

the error message is:

Driver.obj : error LNK2019: unresolved external symbol __CheckForDebuggerJustMyCode referenced in function DriverEntry

Upvotes: 8

Views: 5945

Answers (3)

kgflying
kgflying

Reputation: 244

This is related to the new C++ Just My Code Stepping (JMC) feature in Visual Studio 2017 15.8. Because the feature depends on CRT (C Run-Time Libraries), if the project does not link to CRT, it may hit error LNK2019: unresolved external symbol __CheckForDebuggerJustMyCode.

The workaround is to disable JMC via one of the following methods:

  1. in project settings, "Configuration Properties" -> "C/C++" -> "General": "Support Just My Code Debugging". Change to NO.
  2. in project settings, add /JMC- to "Configuration Properties" -> "C/C++" -> "Command line" -> "Additional Options"

Upvotes: 5

XYZ
XYZ

Reputation: 156

This is related to the new C++ Just My Code Stepping feature in Visual Studio 2017 15.8.

If you get the error open the Project Properties dialog box and set the "Configuration Properties -> C/C++ -> General -> Support Just My Code Debugging" option to no.

Upvotes: 14

Starl1ght
Starl1ght

Reputation: 4493

In Visual Studio 15.8 they introduced JustMyCode debugging, and it actually breaks compilation of a kernel drivers in debug configuration.

It looks like a bug, but the workaround is to compile in release mode for now.

Upvotes: 3

Related Questions