学习SDL记录过程
1、官网下载SDL开源库
http://www.libsdl.org/download-2.0.php
2、选择对应的win版本下载,下载后解压:
3、把x86_64-w64-mingw32 下的 lib 和include 都拷贝到项目文件夹下(我在项目 QtFFmpegPlayer 下 新建了 lib 文件夹,lib 下新建 SDL2 文件 夹,我拷贝到SDL2文件夹下)
4、 在 .pro 文件中引入 注意路径不要写错
INCLUDEPATH += $$PWD/lib/SDL2/include
LIBS += -L$$PWD/lib/SDL2/lib -lSDL2 -lSDL2main
5、测试SDL 是否引入
//main.cpp
#include "mainwindow.h"
#include <iostream>
#include <QApplication>
using namespace std;
extern "C"
{
#include "SDL.h"
#undef main // 不加这句会直接报错
}
int main(int argc, char *argv[])
{
if(SDL_Init(SDL_INIT_VIDEO)) {
cout << "can not int SDL error!!!" << endl;
return -1;
}
else {
cout << "success!!!" << endl;
}
return 0;
}
成功:
6、遇到的报错:
1、#undef main // 不加这句会直接报错
2、路径写错 SDL2 忘记 后面加 /lib