ui笔记-sdl 环境搭建

vscode cpp 插件

ext install cpptools

环境搭建 mac

vscode,sdl2,macbook 10.14.1 (18B75)

brew install sdl2

mkdir myproject
cd myproject
touch main.cpp
touch Makefile
mkdir include
mkdir lib

main.cpp

#include <iostream>
#include <SDL2/SDL.h>
using namespace std;
int main()
{
cout << "Hello World!";
SDL_Init(SDL_INIT_VIDEO);
return 0;
}

把 /usr/local/Cellar/sdl2 下面的 include 和 lib 拷贝到 myproject 下面

Makefile 的内容

game:
g++ main.cpp -o play -I include -L lib -l SDL2-2.0.0

-I (i as in include) tells it additional include directories you want to add
-L tells it additional library directories you want to add
-l (lowercase l as in lib) tells it specific library binaries you want to add

编译项目
make game

运行,看到 “Hello World!” 输出表示 SDL 可用了
./play

环境搭建 linux -尚未验证

sudo apt-get update
sudo apt-get install libsdl2-2.0.0 libsl2-dbg libsdl2-dev
libsdl2-image-2.0-0 libsdl2-image-dbg libsdl2-image-dev

环境搭建 windows