非常特定的未解析的外部符号type_info ::`vftable在/ NODEFAULTLIB可执行文件中使用虚函数时

时间:2015-05-10 00:12:15

标签: c++ c windows linker

我已经使用/ 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;
}

我觉得__tmainCRTStartup中有一些非常明显的错误,因为我相信我已经完成了dll的初始化而不是exe。但是我仍然对我失踪的东西感到有点失落。

1 个答案:

答案 0 :(得分:1)

找到答案,需要在编译时用/ GR -

禁用运行时类型信息