解决链接错误:error LNK2001: 无法解析的外部符号 __iob
該錯(cuò)誤主要是由于靜態(tài)庫(kù)在VC6編譯而主程序在VC2005編譯,大家用的CRT不同。解決辦法,代碼中增加
#ifdef __cplusplus
extern "C"
#endif
FILE _iob[3] = {__iob_func()[0], __iob_func()[1], __iob_func()[2]};
此錯(cuò)誤的產(chǎn)生根源:
在VC6的stdio.h之中有如下定義
_CRTIMP extern FILE _iob[];
#define stdin (&_iob[0])
#define stdout (&_iob[1])
#define stderr (&_iob[2])
stdin、stdout、stderr是通過(guò)查_(kāi)iob數(shù)組得到的。所以,VC6編譯的程序、靜態(tài)庫(kù)只要用到了printf、scanf之類的函數(shù),都要鏈接_iob數(shù)組。
而在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數(shù)組不再是顯式的暴露出來(lái)了,需要調(diào)用__iob_func()函數(shù)獲得。所以vc6的靜態(tài)庫(kù)鏈接VC2005的C運(yùn)行庫(kù)就會(huì)找不到_iob數(shù)組.
通過(guò)重新定義
FILE _iob[3] = {__iob_func()[0], __iob_func()[1], __iob_func()[2]};
就把vc6需要用到的_iob數(shù)組搞出來(lái)了
總結(jié)
以上是生活随笔為你收集整理的解决链接错误:error LNK2001: 无法解析的外部符号 __iob的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 2017招行信用卡申请进度/期限查询方法
- 下一篇: asterisk 互联问题