[SDL] Embed SDL.dll in the .exe

Sylvain Beucler beuc at beuc.net
Wed Sep 26 06:57:30 PDT 2007


On Wed, Sep 26, 2007 at 03:14:25PM +0200, Gerry JJ wrote:
> 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)).

Thanks, I'll dig more into those options.

I'm also having a first clean build by simply adding -lwinmm - I
thought that --static-libs would give me this kind of dependencies
automatically :)

i586-mingw32msvc-gcc -static joytest.c \
  `/usr/local/cross-tools/i386-mingw32msvc/bin/sdl-config --cflags --static-libs` \
  -lwinmm

-- 
Sylvain


More information about the SDL mailing list