Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error LNK2019: unresolved external symbol __CheckForDebuggerJustMyCode referenced in function DriverEntry

Tags:

windows

driver

I write a windows 10 driver.

following is the code, actually the code is a sample of docs.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
like image 602
Joe Xu Avatar asked Aug 15 '18 05:08

Joe Xu


People also ask

Why am I getting external symbol errors in lnk2019?

That's because the definition may be in a different source file or library. If a symbol is referred to but never defined, the linker generates an unresolved external symbol error. Here are some common problems that cause LNK2019:

What is an unresolved external symbol error?

The compiler can identify when a symbol isn't declared, but it can't tell when the symbol isn't defined. That's because the definition may be in a different source file or library. If a symbol is referred to but never defined, the linker generates an unresolved external symbol error. Here are some common problems that cause LNK2019:

How do I fix lnk2019 errors in my build?

Unless i and g are defined in one of the files included in the build, the linker generates LNK2019. You can fix the errors by including the source code file that contains the definitions as part of the compilation. Alternatively, you can pass .obj files or .lib files that contain the definitions to the linker.

Why is lnk2019 not working in Visual Studio?

Here are some common problems that cause LNK2019: The source file that contains the definition of the symbol isn't compiled In Visual Studio, make sure the source file that defines the symbol gets compiled as part of your project. Check the intermediate build output directory for a matching.obj file.


3 Answers

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.

like image 147
XYZ Avatar answered Nov 12 '22 19:11

XYZ


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"
like image 25
kgflying Avatar answered Nov 12 '22 20:11

kgflying


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.

like image 26
Starl1ght Avatar answered Nov 12 '22 20:11

Starl1ght