[SDL] Embed SDL.dll in the .exe

Gerry JJ trick at icculus.org
Wed Sep 26 06:14:25 PDT 2007


Den Wed, 26 Sep 2007 12:02:28 +0200
skrev Sylvain Beucler <beuc at beuc.net>:
> 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?

Yes, it's possible, you just have to be a bit more specific when
telling the linker what you want to do, since -static affects the
entire linking process and not just part of it like you want.  The
linker has some options called -Bstatic and -Bdynamic that can be used
to do exactly what you want, and you can pass args to the linker with
gcc's -Wl arg, with commas in stead of spaces.  So, just surround the
libraries you want to link statically with -Wl,-Bstatic and
-Wl,-Bdynamic:

gcc stuff -Wl,-Bstatic -lSDL etc -Wl,-Bdynamic

You can do this as many times as you want in a link.  A -Wl,-Bdynamic
at the end ensures that gcc won't try to statically link system libs
and such.  If you still get a dynamically linked SDL after this, you
probably just have to sort out the order of the link args (a request
for a lib in a dynamic part after that lib's already been statically
linked will pull it in dynamically as well if possible.  If you've got
false dependencies interfering with your link, -Wl,--as-needed might
help (makes the target only depend on first-level dependencies)).

- Gerry


More information about the SDL mailing list