該錯(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是通過查_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ù)組不再是顯式的暴露出來了,需要調(diào)用__iob_func()函數(shù)獲得。所以vc6的靜態(tài)庫(kù)鏈接VC2005的C運(yùn)行庫(kù)就會(huì)找不到_iob數(shù)組.
通過重新定義
FILE _iob[3] = {__iob_func()[0], __iob_func()[1], __iob_func()[2]};
就把vc6需要用到的_iob數(shù)組搞出來了