該錯誤主要是由于靜態庫在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數組搞出來了