天天看点

解决:无法解析的外部符号__iob_func解决:无法解析的外部符号__iob_func

解决:无法解析的外部符号__iob_func

原文:http://blog.csdn.net/hebbely/article/details/53780562

在使用 VS2015 下使用 libjpeg-turbo 静态库,编译时报错了:
[cpp]  view plain  copy
  1. 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

  1. ACRTIMP_ALT FILE* __cdecl __acrt_iob_func(unsigned);  
  2. #define stdin  (__acrt_iob_func(0))  
  3. #define stdout (__acrt_iob_func(1))  
  4. #define stderr (__acrt_iob_func(2))  
原来在 VS2015 中 

__iob_func 

改成了 

__acrt_iob_func 

,所以我参照《【LNK2019】 无法解析的外部符号 __iob》这篇文章的方法在自己的代码中增加了一个名为 

__iob_func 

转换函数:

[cpp]  view plain  copy

  1. #if _MSC_VER>=1900  
  2. #include "stdio.h"   
  3. _ACRTIMP_ALT FILE* __cdecl __acrt_iob_func(unsigned);   
  4. #ifdef __cplusplus   
  5. extern "C"   
  6. #endif   
  7. FILE* __cdecl __iob_func(unsigned i) {   
  8.     return __acrt_iob_func(i);   
  9. }  
  10. #endif   
再次编译,错误消失。

继续阅读