解决:无法解析的外部符号__iob_func
原文:http://blog.csdn.net/hebbely/article/details/53780562
在使用 VS2015 下使用 libjpeg-turbo 静态库,编译时报错了:
[cpp] view plain copy
- error LNK2019: 无法解析的外部符号 __iob_func,该符号在函数 output_message 中被引用
根据关键字在网上找到一些文章描述了类似的错误,大都是找不到外部符号
__iob
,原因是VS2010上使用了 VC6 编译的 DLL 。虽然与我的情况不同,但是原理是一样的,我遇到的这个问题的原因是 VS2015 下使用VS2010编译的静态库,因为我用的libjpeg-turbo静态库是从官网下载编译好的版本(应该是vs2010这样的版本编译的)。
其实
和
__iob_func
都是用来定义
__iob
stdin,stdout,stderr
,只是不同的VC版本实现方式不同。
下面是VS2015的头文件
中对
corecrt_wstdio.h
stdin,stdout,stderr
定义
[cpp] view plain copy
- ACRTIMP_ALT FILE* __cdecl __acrt_iob_func(unsigned);
- #define stdin (__acrt_iob_func(0))
- #define stdout (__acrt_iob_func(1))
- #define stderr (__acrt_iob_func(2))
原来在 VS2015 中改成了
__iob_func
,所以我参照《【LNK2019】 无法解析的外部符号 __iob》这篇文章的方法在自己的代码中增加了一个名为
__acrt_iob_func
__iob_func
转换函数:
[cpp] view plain copy
- #if _MSC_VER>=1900
- #include "stdio.h"
- _ACRTIMP_ALT FILE* __cdecl __acrt_iob_func(unsigned);
- #ifdef __cplusplus
- extern "C"
- #endif
- FILE* __cdecl __iob_func(unsigned i) {
- return __acrt_iob_func(i);
- }
- #endif
再次编译,错误消失。