错误 LNK2019:在函数 "void __cdecl Padding(int)" 中引用了未解析的外部符号 ___iob_func。

5

使用FTDI API在Visual Studio 2012下编译和链接正常。

但是在VS 2014下,会出现以下错误:

Error LNK2019: unresolved external symbol ___iob_func referenced in function "void __cdecl Padding(int)"

标准库有变化吗?
1个回答

1
是的,标准库已经改变了,而FTDI似乎并不关心 - 至少在CDM2.12.18驱动程序版本中没有关注。
问题描述在这个问题的答案中。 devcon.obj中的void __cdecl Padding(int)函数在ftd2xx.lib中是罪魁祸首。它引用了其中一个宏定义的stdinstdoutstderr。这些宏的内容已经改变了。
既然我们并不真正期望从FTDI库中得到任何I/O,那么我们最好提供可能的最简单实现:
FILE* __cdecl _imp____iob_func() { return 0; }

如果您想要一个能够实现其预期功能的版本:
FILE* __cdecl _imp____iob_func()
{
    struct _iobuf_VS2012 { // ...\Microsoft Visual Studio 11.0\VC\include\stdio.h #56
        char *_ptr;
        int   _cnt;
        char *_base;
        int   _flag;
        int   _file;
        int   _charbuf;
        int   _bufsiz;
        char *_tmpfname; };
    // VS2015 has FILE = struct {void* _Placeholder}

    static struct _iobuf_VS2012 bufs[3];
    static char initialized = 0;

    if (!initialized) {
        bufs[0]._ptr = stdin->_Placeholder;
        bufs[1]._ptr = stdout->_Placeholder;
        bufs[2]._ptr = stderr->_Placeholder;
        initialized = 1;
    }

    return (FILE*)&bufs;
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接