c++ - 非常具体的未解析外部符号 type_info::`vftable 在/NODEFAULTLIB 可执行文件中使用虚拟函数时

标签 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的初始化。但我仍然对我所缺少的东西感到有点迷失。

最佳答案

找到答案,需要在编译时使用/GR- 禁用运行时类型信息

关于c++ - 非常具体的未解析外部符号 type_info::`vftable 在/NODEFAULTLIB 可执行文件中使用虚拟函数时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30146374/

相关文章:

c++ - 编译错误。定义不匹配。无效(*)(无效*)

ruby - IO.popen 不工作蹩脚的标准输入和标准输出编码

python - Twisted Python 客户端/服务器的 Kerberos 身份验证

php - 使用 php 获取窗口标题在浏览器调用中不起作用

C++ 折叠表达式与用户定义的类

c++ - 当不需要完整计算时从某种方法提前返回

c++ - 将float转换为int,当int溢出范围时,将其设为max int或min int

c - epoll ET,我应该在监听套接字上订阅什么事件?

c - 不同宽度数据类型上位移运算符的安全性

编译器错误: wasted space