- 1 year ago
How to solve LNK2019 unresolved external symbol DriverEntry referenced in function GsDriverEntry?
The "LNK2019 unresolved external symbol" error occurs in Visual Studio when the linker cannot find the definition for a symbol referenced in your code. In the case of a driver project, the error often occurs when the DriverEntry
function is not correctly defined or not exported for the driver to be loaded properly.
To solve the "LNK2019 unresolved external symbol DriverEntry" error in a Windows driver project, follow these steps:
Ensure Proper DriverEntry Definition:
Verify that theDriverEntry
function is correctly defined with the correct parameters and return type. In a Windows driver, theDriverEntry
function should have the following signature:cppNTSTATUS DriverEntry(
_In_ PDRIVER_OBJECT DriverObject,
_In_ PUNICODE_STRING RegistryPath
);
Make sure your
DriverEntry
function matches this signature.Export DriverEntry:
For the driver to be loaded successfully, theDriverEntry
function needs to be exported so that it can be found by the operating system. In C/C++, you can use the__declspec(dllexport)
attribute to export the function.Add the following line before the
DriverEntry
function definition:cpp__declspec(dllexport) NTSTATUS DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath);
This tells the compiler to export the
DriverEntry
function so that the linker can find it.Check Project Configuration:
Ensure that your driver project is correctly configured with the appropriate build settings. For a driver project, the configuration should be set to target the correct version of Windows and the appropriate driver type (e.g., KMDF or WDM).Include Necessary Libraries:
If your driver relies on any additional libraries or object files, ensure that they are included in the project and that their paths are correctly specified in the project settings.Check Build Order:
Verify that your driver project is built before any other projects that may depend on it. In Visual Studio, you can manage the build order of projects in the solution properties.Clean and Rebuild:
After making changes to your driver code or project settings, clean the solution and then rebuild it to ensure that all changes take effect.
By following these steps, you should be able to resolve the "LNK2019 unresolved external symbol DriverEntry" error in your Windows driver project. If the error persists, carefully review your code and project settings to identify any issues with the DriverEntry
function and its exporting. Additionally, check for any missing dependencies or incorrect build configurations that could be causing the linker error.