如何在 Windows 上静态编译 SDL 游戏

发布于 2024-07-06 01:23:22 字数 227 浏览 13 评论 0原文

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

请注意,我在这里讨论的不是许可。 源代码将开放,因此 sdl 的 GPL/LGPL 性不相关。

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.

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

悍妇囚夫 2024-07-13 01:23:22

编译项目时,您只需对 makefile 进行一些更改。

  • 代替sdl-config --libs,使用sdl-config --static-libs
  • 包围上述sdl-config --static-的使用libs-Wl,-Bstatic-Wl,-Bdynamic。 这告诉 GCC 强制静态链接,但仅限于它们之间指定的库。

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

SDLLIBS=`sdl-config --libs`

将其更改为:

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

这些实际上与你在类 Unix 系统上应该做的事情相同,但如果你使用,它通常不会在类 Unix 系统上导致那么多错误GCC 的更简单的 -static 标志,就像在 Windows 上一样。

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

  • 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.

If your makefile currently looks like:

SDLLIBS=`sdl-config --libs`

Change it to:

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

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.

空名 2024-07-13 01:23:22

通过这个SDL邮件列表帖子似乎sdl 开发工具附带了 sdl-config 脚本,您可以将其与 --static-libs 标志一起使用来确定需要使用哪些链接器标志。

Via this SDL mailing list post it seems that the sdl development tools ship with a sdl-config script that you can use with the --static-libs flag to determine what linker flags you need to use.

执妄 2024-07-13 01:23:22

环境:VMWare虚拟机,Windows 7 x64,设备我们Dev c++ build 7.4.2.569,编译g++(tdm-1) 4.6.1

一次,SDL2-2.0.3 API作为配置安装Dev c++不是很清楚我所做的事情,因为传统需要命令行。

第一个问题是,Windows 7 似乎改变了方法,他们开始参加他的舞会。 存货。 参考号 https://stackoverflow.com/users/464581/cheers-and-hth-alf

之后第一个障碍,SDL_platform.h 太糟糕了,它又掉下来了,我不记得在哪里下载的,但下一个在指定版本中不起作用。

我们必须将 SDL2.h ls 放在可执行文件的目录中。

D:\prg_desa\zsdl2>g++ bar.cpp main.cpp -o pepe1 -ID:\SDL2-2.0.3\i686-w64-mingw32\include\SDL2 -LD:\SDL2-2.0.3\i686 -w64-mingw32\lib -lmingw32 -lSDL2main -lSDL2 -mwindow

我终于编译并进行了 SDL2 测试。

Environment: VMWare Virtual Machine with Windows 7 x64 and Equipment we Dev c + + build 7.4.2.569, complilador g+ + (tdm-1) 4.6.1

Once, SDL2-2.0.3 API installed as configuration Dev c ++ is not very clear what I've done as tradition requires command line.

The first problem is that Windows 7 appears to have changed the methodology and they go to his ball. Inventory. Ref. https://stackoverflow.com/users/464581/cheers-and-hth-alf

After the first hurdle, SDL_platform.h is that bad, it's down another, I do not remember where I downloaded, but the next does not work in the indicated version.

We must put SDL2.h ls in the directory of the executable.

D:\prg_desa\zsdl2>g++ bar.cpp main.cpp -o pepe1 -ID:\SDL2-2.0.3\i686-w64-mingw32\include\SDL2 -LD:\SDL2-2.0.3\i686-w64-mingw32\lib -lmingw32 -lSDL2main -lSDL2 -mwindow

I've finally compiled and works SDL2 testing.

傾城如夢未必闌珊 2024-07-13 01:23:22

这是因为 SDL 库遵循 LGPL 许可证。

如果你想静态链接这些库(如果你重新编译它们就可以做到这一点。尽管它需要对 makefile 进行一些修改),你也必须将你的游戏置于一些兼容的开源许可证下。

SDL-lib 作为共享库出现,因为大多数使用它们的程序都是闭源的。 二进制发行版以大多数人需要的形式出现。

That's because the SDL libs are under the LGPL-license.

If you want to static link the libs (you can do that if your recompile them. It needs some hacking into the makefiles though) you have to place your game under some compatible open source license as well.

The SDL-libs come as shared libraries because most programs that use them are closed source. The binary distribution comes in a form that most people need.

神经暖 2024-07-13 01:23:22

在我的系统 (Ubuntu) 上,我必须使用以下标志:

-Wl,Bstatic -lSDL_image `sdl-config --libs` -lpng12 -lz -ltiff -ljpeg -lasound -laudio -lesd -Wl,-Bdynamic `directfb-config --libs` -lpulse-simple -lcaca -laa -ldl

将 SDL、SDL_image 及其许多依赖项链接为静态。 libdl 永远不需要静态,因此制作使用 SDL_image 的完全静态二进制文件是一个糟糕的主意。 pulse、caca、aa 和 directfb 可能可以设为静态。 我还没有走得足够远来弄清楚它们。

On my system (Ubuntu) I have to use the following flags:

-Wl,Bstatic -lSDL_image `sdl-config --libs` -lpng12 -lz -ltiff -ljpeg -lasound -laudio -lesd -Wl,-Bdynamic `directfb-config --libs` -lpulse-simple -lcaca -laa -ldl

That links SDL, SDL_image, and many of their dependencies as static. libdl you never want static, so making a fully-static binary that uses SDL_image is a poor idea. pulse,caca,aa, and directfb can probably be made static. I haven't got far enough to figure them out yet.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文