如何在 Windows 上静态编译 SDL 游戏 [英] How to statically compile an SDL game on Windows

查看:46
本文介绍了如何在 Windows 上静态编译 SDL 游戏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试为我的 Windows 游戏制作一个静态链接的单一二进制"版本.我想与 sdl、sdl_image 和 sdl_mixer 链接,它们又会引入一些支持库.不幸的是,我还没有找到一种方法让它们全部使用 cygwin/mingw/gcc 进行编译和链接.据我所知,所有现有的公共版本都只是共享库/dll.

I have been trying to produce a statically linked "single binary" version of my game for windows. I want to link with sdl, sdl_image and sdl_mixer which in turn pull in a few support libraries. Unfortunately I haven't found a way to get them all to compile and link using cygwin/mingw/gcc. As far as I can tell all existing public versions are only shared libraries / dlls.

请注意,我在这里不是在谈论许可.源将是开放的,因此与 sdl 的 GPL/LGPL 无关.

Please note that I'm not talking about licencing here. The source will be open thus the GPL/LGPLness of sdl is not relevant.

推荐答案

在编译项目时,您只需对 makefile 进行几处更改.

When compiling your project, you need to make just a couple changes to your makefile.

  • 代替 sdl-config --libs,使用 sdl-config --static-libs
  • -Wl,-Bstatic-Wl,-Bdynamic包围上述sdl-config --static-libs的使用代码>.这告诉 GCC 强制静态链接,但仅限于它们之间指定的库.
  • Instead of sdl-config --libs, use sdl-config --static-libs
  • Surround the use of the above-mentioned sdl-config --static-libs with -Wl,-Bstatic and -Wl,-Bdynamic. This tells GCC to force static linking, but only for the libraries specified between them.

如果您的 makefile 当前看起来像:

If your makefile currently looks like:

SDLLIBS=`sdl-config --libs`

改为:

SDLLIBS=-Wl,-Bstatic `sdl-config --static-libs` -Wl,-Bdynamic

这些实际上与您在类 Unix 系统上应该做的事情相同,但是如果您使用更简单的 -static<,通常不会在类 Unix 系统上引起那么多错误/code> 标记到 GCC,就像在 Windows 上一样.

These are actually the same things you should do on Unix-like systems, but it usually doesn't cause as many errors on Unix-likes if you use the simpler -static flag to GCC, like it does on Windows.

这篇关于如何在 Windows 上静态编译 SDL 游戏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆