无法解析的外部符号__imp__fprintf和 __imp____iob_func,SDL2

本文详细介绍了在使用Visual Studio 2015编译SDL2项目时遇到的链接错误,如无法解析的外部符号__imp__fprintf和__imp____iob_func。错误源于VS2015中stdin, stdout, stderr的新定义方式与旧版不兼容。文章提供了两种解决方案:一是定义__iob_func()函数,二是添加legacy_stdio_definitions.lib到链接器选项,并建议重新编译SDL2以避免此类问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1>SDL2main.lib(SDL_windows_main.obj) : error LNK2019: 无法解析的外部符号 __imp__fprintf,该符号在函数 _ShowError 中被引用
1>SDL2main.lib(SDL_windows_main.obj) : error LNK2019: 无法解析的外部符号 __imp____iob_func,该符号在函数 _ShowError 中被引用
1>G:\ffmpeg\simplest_ffmpeg_player-master\Debug\simplest_ffmpeg_player2_su.exe : fatal error LNK1120: 2 个无法解析的外部命令

 

在 Visual Studio 2015中,标准stdin,stderr,stdout定义如下:

#define stdin (__acrt_iob_func(0))
#define stdout (__acrt_iob_func(1))
#define stderr (__acrt_iob_func(2))

但在以前,它们被定义为:

#define stdin (&__iob_func()[0])
#define stdout (&__iob_func()[1])
#define stderr (&__iob_func()[2])

因为在这__iob_func不再定义了,这会导致使用以前版本的Visual Studio 版本编译的. lib 文件的链接错误。

为了解决这个问题,你可以尝试定义__iob_func(),它应该返回一个包含 {*stdin,*stdout,*stderr}的array 。

关于stdio函数( 在我看来是 sprintf() )的其他链接错误,可以将legacy_stdio_definitions.lib 添加到链接器选项。

FILE _iob[] = {*stdin, *stdout, *stderr};
extern"C" FILE * __cdecl __iob_func(void)
{
 return _iob;
}

另外一个解决方案就是,用vs2015重新编译SDL2,使用其生成的静态库

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值