[SDL] Embed SDL.dll in the .exe

Sylvain Beucler beuc at beuc.net
Wed Sep 26 03:02:28 PDT 2007


Hi!

On Wed, Sep 26, 2007 at 10:32:51AM +0200, David Olofson wrote:
> On Wednesday 26 September 2007, Sylvain Beucler wrote:
> > Hi,
> > 
> > I'm porting a C game to SDL + some libraries (SDL_mixer, SDL_ttf,
> > SDL_gfx).
> > 
> > I'd like to compile a .exe that includes SDL.dll, SDL_mixer.dll,
> > etc., 
> > so that users who want to use the improved SDL version just have to
> > drop-in 1 .exe file, and do not need to install all the .dll.
> 
> This sounds very backwards to me... This is exactly why you do NOT 
> want a statically linked executable! :-)
> 
> Also, you do realize that releasing only statically linked executables 
> of a closed source application violates the licence of LGPL libs 
> (like SDL), right? You need to provide a dynamically linked version 
> as well, or linkable object files, or (obviously) the source code, or 
> otherwise ensure that users can use your software with whatever SDL 
> version they want.

No surprise, I was pretty sure I'd get advice on why I don't want to
do a static compilation - except I do want that :)

The C game is GNU FreeDink, it is released under the GNU GPL:
http://git.sv.gnu.org/gitweb/?p=freedink.git;a=summary

I plan to provide several packages, statically compiled and
dynamically compiled -- and people are still not happy they'll just
./configure && make && make install ;)

Btw, static compilation of proprietary SDL apps does not break the
LGPL if you provide the .o and every compilation tools needed by the
user when he wants to use another version of SDL with your app. Using
dynamic linking is the easiest way to comply with the LGPL, but not
the only one!

Now for the technical part:

> > I'm using mingw gcc, but no luck so far with -static (gcc want to
> > include W32 API functions statically such as _mciSendCommandA at 16 and
> > obviously can't find them).
> > 
> > 
> > Anybody has experience with this? Is that possible?
> 
> You can specify more exactly how to link each lib by linking in 
> multiple stages if you just compile to object files and then use 'ld' 
> for linking. I think it might work if you first create an object 
> linked with all the static stuff, and then link that with anything 
> you still want dynamic, to produce the executable.
> 
> If all else fails, simply don't have dynamically linked libs installed 
> when you link your executable. The linker will have no choice but to 
> use the static versions. :-)

I indeed use separate compilation and link the .o with MinGW ld.

I don't think I can compile a fully-static .exe, because .exe will
always require external Windows .dll's, which I don't have the .a for.

I'd like to include libSDL (and libSDL_mixer, etc.) in my .exe while
still keeping their external dependencies (to the Windows MCI and
timer subsystems, namely).

I tried a non-static build and giving the (cross-compiled) libSDL.a to
ld (instead of -lSDL), but it still required those external
dependencies.

I look for a kind of "partially static" compilation, as if SDL was
part of my own code, but I don't have enough knowledge of GCC to know
how that can be done.

Do you know if that's possible?

-- 
Sylvain


More information about the SDL mailing list