LNK2001: 无法解析的外部符号 __iob问题的解决方法
注:我用的方法2解决的
1、缺少libc.lib 解决这个问题的方法是去掉链接到libc.lib,具体地点:项目-〉属性-〉配置属性-〉链接器-〉忽略特定库。
2、unresolved external symbol __iob 这个__iob找不到的问题费了我大部分的时间。跟踪到stdio.h文件,发现那里有个关于iob的宏,终于搞定。加入一句话到.cpp文件中:extern "C" { FILE _iob[3] = {__iob_func()[0], __iob_func()[1], __iob_func()[2]}; }
3、NULL iterator STL已经不能有NULL迭代器这么一说了,想想也对,在NULL迭代器上进行++或--之类的是不成立的。
4、结构体默认函数 在VC6中,结构体的默认运算符==或者<之类的如果不实现也可以作为STL元素放入list等容器中。但VC8不行了,因为它已经不再为结构体生成缺省的操作符函数。
该错误主要是由于静态库在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数组搞出来了