根据雷神教程中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 }; }
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;
}