[SDL]VS2019下SDL环境配置注意点

根据雷神教程中sdl的配置做下去还是会出现如下的问题

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 中被引用 

查了一下是如下的问题:

定义方式发生了变换,标准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])

以上部分来自

无法解析的外部符号__imp__fprintf和 __imp____iob_func,SDL2_宏的博客-CSDN博客

解决

只需要在代码中添加:

#pragma comment(lib,"legacy_stdio_definitions.lib")
extern "C" { FILE __iob_func[3] = { *stdin,*stdout,*stderr }; }

以上来自error LNK2019: 无法解析的外部符号 __imp___iob_func,该符号在函数 amqp_abort 中被引用,无法解析的外部符号 __imp_vfprintf_学会简单的博客-CSDN博客

sdl环境配置调试代码即运行结果

调试代码:

#include<stdio.h>
#include<stdlib.h>
extern "C"
{
#include "SDL2/SDL.h"
}

#pragma comment(lib,"legacy_stdio_definitions.lib")
extern "C" { FILE __iob_func[3] = { *stdin,*stdout,*stderr }; }

int main(int argc, char* argv[])
{
	if (SDL_Init(SDL_INIT_VIDEO)) {
		printf("Could not initialize SDL - %s\n", SDL_GetError());
	}
	else {
		printf("Success init SDL");
	}
	return 0;
}

运行结果:

  • 5
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值