首页 > 解决方案 > 编译没有 kernel32.lib 的 c 程序时出现链接错误

问题描述

我想创建只使用 ntdll 并对其使用安全检查的应用程序。但是当我删除 kernel32.lib 或取消选中“从父级或项目默认值继承”时,我在构建项目时会出现链接错误。 链接错误

#include <Windows.h>
#include <processthreadsapi.h>
#include <vcruntime.h>
ULONG WINAPI NtGetCurrentProcessorNumber(void);
void main()
{
    int a = 2;
    int b = 5;
    int sum = a + b;
    int Number = NtGetCurrentProcessorNumber();
    while (1)
    {

    }
}

void NtProcessStartup(PVOID DriverObject, PVOID RegistryPath)
{
    __security_init_cookie();
    //__security_check_cookie();
    main();
}

这是一个本机项目,当我在编译器设置中删除“安全检查”开关并删除“__security_init_cookie”功能时工作正常。这个项目链接到 ntdll.lib

谁能帮我?

标签: windowslinkercrtkernel32usermode

解决方案


当您使用安全检查时,__security_xx功能会链接到您的模块。链接器错误表示gs_support.obj__security_xx函数所在的位置)、需要QueryPerformanceCounter和其他列出的函数。QueryPerformanceCounter 驻留在 kernel32中,因此在使用安全检查时需要与它链接。


推荐阅读