您的位置:首页 > 其它

解决链接错误:error LNK2001: 无法解析的外部符号 __iob

2014-01-28 15:17 507 查看
该错误主要是由于静态库在VC6编译而主程序在VC2005编译,大家用的CRT不同。解决办法,代码中增加

#ifdef __cplusplus

extern "C"

#endif

FILE _iob[3] = {__iob_func()[0], __iob_func()[1], __iob_func()[2]};

此错误的产生根源:

在VC6的stdio.h之中有如下定义

_CRTIMP extern FILE _iob[];

#define stdin (&_iob[0])

#define stdout (&_iob[1])

#define stderr (&_iob[2])

stdin、stdout、stderr是通过查_iob数组得到的。所以,VC6编译的程序、静态库只要用到了printf、scanf之类的函数,都要链接_iob数组。

而在vc2005中,stdio.h中变成了

_CRTIMP FILE * __cdecl __iob_func(void);

#define stdin (&__iob_func()[0])

#define stdout (&__iob_func()[1])

#define stderr (&__iob_func()[2])

_iob数组不再是显式的暴露出来了,需要调用__iob_func()函数获得。所以vc6的静态库链接VC2005的C运行库就会找不到_iob数组.

通过重新定义

FILE _iob[3] = {__iob_func()[0], __iob_func()[1], __iob_func()[2]};

就把vc6需要用到的_iob数组搞出来了
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐