windows 使用 cmake 方式源码编译 SDL2

说明

想在 windows 下源码方式编译 SDL2,生成 SDL2 的 lib 静态库,release 版本

编译环境: win10

  • SDL 版本:当前 SDL github 最新版本,SDL2 分支

  • 获取 SDL2 源码

  • SDL 的官方网站 https://www.libsdl.org/

  • 通过 SDL 的官方网站,了解到获取 SDL 的源码,可以通过 github

git clone https://github.com/libsdl-org/SDL.git

由于当前 SDL 的主线(master 分支)为 SDL3,因此可以切换 git 分支到 SDL2

git checkout SDL2

cmake 编译

  • windows 上可以使用 visual studio 进行编译,也可以使用 x86_64-w64-mingw32

  • 当前使用 x86_64-w64-mingw32

  • 下载 x86_64-w64-mingw32,比如 x86_64-8.1.0-release-win32-seh-rt_v6-rev0.zip,解压并设置好环境变量,比如 D:\tools\mingw64\bin

  • windows 安装 cmake,然后设置好环境变量,这样 cmd.exe 可以执行 cmake 命令

进入 SDL 目录,cmake 编译 SDL2 的命令行

c 复制代码
mkdir build
cd build

cmake -G "MinGW Makefiles" ..
cmake --build . --config Release --verbose
cmake --install . --prefix _install
  • cmake -G "MinGW Makefiles" ..

  • cmake --build . --config Release --verbose

  • cmake --install . --prefix _install

  • 这样 SDL2 编译为 lib 库,并安装到指定的目录下,比如 build\_install 目录下了
相关推荐
阿白的白日梦1 小时前
winget基础管理---更新/修改源为国内源
windows
埃博拉酱4 天前
VS Code Remote SSH 连接 Windows 服务器卡在"下载 VS Code 服务器":prcdn DNS 解析失败的诊断与 BITS 断点续传
windows·ssh·visual studio code
唐宋元明清21885 天前
.NET 本地Db数据库-技术方案选型
windows·c#
加号35 天前
windows系统下mysql多源数据库同步部署
数据库·windows·mysql
tryCbest5 天前
Windows环境下配置pip镜像源
windows·pip
呉師傅5 天前
火狐浏览器报错配置文件缺失如何解决#操作技巧#
运维·网络·windows·电脑
百事牛科技5 天前
保护文档安全:PDF限制功能详解与实操
windows·pdf
一个人旅程~5 天前
如何用命令行把win10/win11设置为长期暂停更新?
linux·windows·经验分享·电脑
一个假的前端男5 天前
[特殊字符] Flutter 安装完整指南 Windows—— 2026最新版
windows·flutter
倚肆5 天前
在 Windows Docker 中安装并配置 Nginx (映射 Windows 端口与路径)
windows·nginx·docker