VS2015下解決:error LNK2019: 無法解析的外部符號 __iob_func
阿新 • • 發佈:2019-01-06
在使用VS2015下使用libjpeg-turbo靜態庫,編譯時報錯了:
error LNK2019: 無法解析的外部符號 __iob_func,該符號在函式 output_message 中被引用
根據關鍵字在網上找到一些文章描述了類似的錯誤,大都是找不到外部符號__iob
,原因是VS2010上使用了VC6編譯的DLL。雖然與我的情況不同,但是原理是一樣的,我遇到的這個問題的原因是VS2015下使用VS2010編譯的靜態庫,因為我用的libjpeg-turbo靜態庫是從官網下載編譯好的版本(應該是vs2010這樣的版本編譯的)。
其實__iob_func
和__iob
都是用來定義stdin,stdout,stderr
下面是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))
原來在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 */
再次編譯,錯誤消失。
其實吧,因為我用的libjpeg-turbo靜態庫是從官網下載編譯好的版本(應該是vs2010這樣的版本編譯的),所以才有這個問題,如果自己重新把libjpeg-turbo的原始碼在vs2015下重新編譯,就不會存在這個問題了。