IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    [转]VS2015下解决:error LNK2019: 无法解析的外部符号 __iob_func

    caimouse发表于 2016-11-16 18:13:14
    love 0

    在使用VS2015下编译SDCC时,编译时报错了:

    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定义

    _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))
    • 1
    • 2
    • 3
    • 4
    • 5
    • 1
    • 2
    • 3
    • 4
    • 5

    原来在VS2015中__iob_func改成了__acrt_iob_func,所以我参照《【LNK2019】 无法解析的外部符号 __iob》这篇文章的方法在自己的代码中增加了一个名为__iob_func转换函数:

    /*
     * 当libjpeg-turbo为vs2010编译时,vs2015下静态链接libjpeg-turbo会链接出错:找不到__iob_func,
     * 增加__iob_func到__acrt_iob_func的转换函数解决此问题,
     * 当libjpeg-turbo用vs2015编译时,不需要此补丁文件
     */
    #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 /* _MSC_VER>=1900 */
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16

    再次编译,错误消失。

    其实吧,因为我用的libjpeg-turbo静态库是从官网下载编译好的版本(应该是vs2010这样的版本编译的),所以才有这个问题,如果自己重新把libjpeg-turbo的源码在vs2015下重新编译,就不会存在这个问题了。



沪ICP备19023445号-2号
友情链接