非常特定的未解决的外部符号type_info ::`vftsable在 /nodefaultlib中使用虚拟函数时

Very Specific Unresolved External Symbol type_info::`vftable When using Virtual Functions in /NODEFAULTLIB executable

本文关键字:nodefaultlib 函数 虚拟 vftsable 外部 未解决 符号 type 非常 info      更新时间:2023-10-16

我已经使用/nodefaultlib构建了一个可执行文件,但我觉得我在winmain之前的入口点上做错了一些事情,因为每当我使用虚拟方法时,我都会收到链接器错误:

error LNK2001: unresolved external symbol "const type_info::`vftable'" (??_7type_info@@6B@)

这是我的入口点:

typedef void (__cdecl *_PVFV)(void);
typedef int (__cdecl *_PIFV)(void);
// Standard C++ Runtime (STD CRT) __xc_a points to beginning of initializer table
#pragma data_seg(".CRT$XCA")
_PVFV __xc_a[] = { 0 };
// Standard C++ Runtime (STD CRT) __xc_z points to end of initializer table
#pragma data_seg(".CRT$XCZ")
_PVFV __xc_z[] = { 0 };
#pragma data_seg(".CRT$XIA")
_PIFV __xi_a[] = {0};
#pragma data_seg(".CRT$XIZ")
_PIFV __xi_z[] = {0};
#pragma data_seg(".CRT$XPA")
_PVFV __xp_a[] = {0};
#pragma data_seg(".CRT$XPZ")
_PVFV __xp_z[] = {0};
#pragma data_seg(".CRT$XTA")
_PVFV __xt_a[] = {0};
#pragma data_seg(".CRT$XTZ")
_PVFV __xt_z[] = {0};
#pragma data_seg()
#pragma comment(linker, "/MERGE:.CRT=.rdata")
#pragma comment(linker, "/MERGE:.rdata=.data")
// function pointer table to global deinitializer table
static _PVFV * pf_atexitlist = 0;
// Maximum entries allowed in table
static unsigned max_atexitlist_entries = 32;
// Current amount of entries in table //
static unsigned cur_atexitlist_entries = 0;

void __cdecl _initterm ( _PVFV *pfbegin, _PVFV *pfend ) 
{
    for ( ; pfbegin < pfend; pfbegin++ ) 
    {
        if ( *pfbegin != nullptr ) (**pfbegin)();
    }
}
void _cdecl Exit () {
    // Go through the list, and execute all global exit routines
    while (cur_atexitlist_entries--) {
            // execute function
            (*(--pf_atexitlist)) ();
    }
}
void _cdecl InitializeConstructors()
{
   _initterm(__xc_a, __xc_z); 
}

int WINAPI __tmainCRTStartup(void) 
{
//This is obviously lacking
    InitializeConstructors();
    WinMain((HINSTANCE)0x400000,0,0,0);
    Exit ();
    return 0;
}

我觉得__tmaincrtastup中有很明显的问题,因为我相信我已经完成了DLL而不是EXE的初始化。但是我仍然对我缺少的东西有些迷失。

找到答案,需要在编译中禁用/gr-

中禁用运行时类型的信息

/gr-还为我修复了它,与默认lib链接的情况相同,请确保您在MSVC中完全清除呼叫会议字段。