c++ - VS 2010 : error LNK2019: unresolved external symbol "extern "C"void * __cdecl

标签 c++ c visual-studio-2010 linker-errors

我是 C++ 新手,我尝试复制此代码并在 Visual Studio 2010 中运行。但它给出了未解析的 extern 'c' 错误和另一个未解析的标记“extern”C”,如代码下面列出的。

这是导致错误的代码:

#ifdef _MANAGED     // Works only with managed C++
#pragma once
#pragma managed(push, on)
#include <stdlib.h>     //free

typedef void (__cdecl *_PVFV)(void);
extern "C" void * __cdecl _decode_pointer(void *);
extern "C" void * __cdecl _encoded_null();

// crtdll.c
extern "C" _PVFV *__onexitbegin;
extern "C"  _PVFV *__onexitend;



void CrtDestroyStatics(void)
{
    _PVFV * onexitbegin = (_PVFV *)_decode_pointer(__onexitbegin);
    if (onexitbegin)
    {
        _PVFV * onexitend = (_PVFV *)_decode_pointer(__onexitend);
        _PVFV function_to_call = NULL;

        /* save the start and end for later comparison */
        _PVFV * onexitbegin_saved = onexitbegin;
        _PVFV * onexitend_saved = onexitend;

        while (1)
        {
            _PVFV * onexitbegin_new = NULL;
            _PVFV * onexitend_new = NULL;

            /* find the last valid function pointer to call. */
            while (--onexitend >= onexitbegin && (*onexitend == NULL || *onexitend == _encoded_null()))
            {
                /* keep going backwards. */
            }

            if (onexitend < onexitbegin)
            {
                /* there are no more valid entries in the list, we are done. */
                break;
            }

            /* cache the function to call. */
            function_to_call = (_PVFV)_decode_pointer(*onexitend);

            /* mark the function pointer as visited. */
            *onexitend = (_PVFV)_encoded_null();

            /* call the function, which can eventually change __onexitbegin and __onexitend */
            (*function_to_call)();

            onexitbegin_new = (_PVFV *)_decode_pointer(__onexitbegin);
            onexitend_new = (_PVFV *)_decode_pointer(__onexitend);

            if ( ( onexitbegin_saved != onexitbegin_new ) || ( onexitend_saved != onexitend_new ) )
            {
                /* reset only if either start or end has changed */
                 __onexitbegin = onexitbegin_saved = onexitbegin_new;
                 __onexitend = onexitend_saved = onexitend_new;
            }

            break;
        }
        /*
        * free the block holding onexit table to
        * avoid memory leaks.  Also zero the ptr
        * variables so that they are clearly cleaned up.
        */

        free ( onexitbegin ) ;

        __onexitbegin = __onexitend = (_PVFV *)_encoded_null();
    }

} //CrtDestroyStatics

#pragma managed(pop)
#endif

这是链接器错误:

Error   4   error LNK2019: unresolved external symbol "extern "C" void * __cdecl _decode_pointer(void *)" (?_decode_pointer@@$$J0YAPEAXPEAX@Z) referenced in function "void __cdecl CrtDestroyStatics(void)" (?CrtDestroyStatics@@$$FYAXXZ)
Error   3   error LNK2028: unresolved token (0A000F2F) "extern "C" void * __cdecl _decode_pointer(void *)" (?_decode_pointer@@$$J0YAPEAXPEAX@Z) referenced in function "void __cdecl CrtDestroyStatics(void)" (?CrtDestroyStatics@@$$FYAXXZ)

尽管我在链接器->输入中为附加依赖项继承了这些库值

kernel32.lib
user32.lib
gdi32.lib
winspool.lib
comdlg32.lib
advapi32.lib 

请告诉我我犯了什么错?

最佳答案

如果 _decode_poiner 在您的 kernel32 中不可用,则您的配置似乎未正确设置。如果您有旧版本的 VS 并且已升级,请确保链接器没有指向旧环境。

您可以查看here有关如何解决此问题的更多信息。

关于c++ - VS 2010 : error LNK2019: unresolved external symbol "extern "C"void * __cdecl,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22604972/

相关文章:

c++ - MFC VC++ 自定义复选框图像

c++ - 始终输出到屏幕并允许重定向

c - C 语言维吉尼亚密码

c# - "Publish Now"按钮不起作用,但构建 > 发布可以

c++ - 派生类赋值运算符在base中的使用

c++ - 为什么在此代码中隐式转换为常量迭代器会失败?

c++ - 尝试使用 OpenGL 时出错

c - LKM 崩溃取决于硬件?

c# - 在同一解决方案中将用户控件从一个项目复制到另一个项目

visual-studio - 在 VS 中,使用控制台进行断点打印