How to statically link to SDL?

Hello all,

For a couple of months now I’ve been distributing a front-end to xmame that I
wrote under the GPL. This front-end heavily uses the different SDL libraries.
As some people have complained about having trouble getting all the right
libraries installed I was wondering how I’d go about creating a statically
linked executable to distribute. Which g++ options should I be using, and
under what license would such a program be distributable?

Regards,

Pieter Hulshoff

Pieter Hulshoff wrote:

was wondering how I’d go
about creating a statically linked executable to distribute. Which g++
options should I be using, and under what license would such a program
be distributable?

just add the -static option before libs that you want to link
statically, when calling g++.

there is no problem with the license as long as the source stays
available (read GPL). for binary only programms you have to provide the
object files, when linking statically against LGPL code.

clemens

I get a ton of ‘undefined reference’ messages to many SDL functions (even
SDL_init).

I’ve tried:
g++ -static -lSDL -static -lSDL_image -static -lSDL_mixer -static -lSDL_ttf -o
mamed classes.o fileio.o gui.o io.o mamed.o
and
g++ -static -lSDL -lSDL_image -lSDL_mixer -lSDL_ttf -o mamed classes.o
fileio.o gui.o io.o mamed.o
and
g++ -static sdl-config --static-libs --cflags -o mamed classes.o fileio.o
gui.o io.o mamed.o

Any thoughts on where I’m going wrong?

Regards,

Pieter HulshoffOn Saturday 13 December 2003 11:17, Clemens Kirchgatterer wrote:

Pieter Hulshoff wrote:

was wondering how I’d go
about creating a statically linked executable to distribute. Which g++
options should I be using, and under what license would such a program
be distributable?
just add the -static option before libs that you want to link
statically, when calling g++.

Perhaps you could try this:
g++ classes.o fileio.o gui.o io.o mamed.o -o mamed sdl-config --static-libs --cflags --libs -lSDL_mixer -lSDL_image -lSDL_ttf

I tried it with -static (for the SDL_mixer, SDL_image and SDL_ttf libs),
but I also get undefined references. Maybe this is already linked
statically somehow by sdl-config, but I doubt it… Well, at least SDL
itself works that way :wink:

Bernhard

Pieter Hulshoff wrote:> On Saturday 13 December 2003 11:17, Clemens Kirchgatterer wrote:

Pieter Hulshoff wrote:

was wondering how I’d go
about creating a statically linked executable to distribute. Which g++
options should I be using, and under what license would such a program
be distributable?

just add the -static option before libs that you want to link
statically, when calling g++.

I get a ton of ‘undefined reference’ messages to many SDL functions (even
SDL_init).

I’ve tried:
g++ -static -lSDL -static -lSDL_image -static -lSDL_mixer -static -lSDL_ttf -o
mamed classes.o fileio.o gui.o io.o mamed.o
and
g++ -static -lSDL -lSDL_image -lSDL_mixer -lSDL_ttf -o mamed classes.o
fileio.o gui.o io.o mamed.o
and
g++ -static sdl-config --static-libs --cflags -o mamed classes.o fileio.o
gui.o io.o mamed.o

Any thoughts on where I’m going wrong?

Regards,

Pieter Hulshoff


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

Hmm, it compiles, but how can I tell if it’s actually statically linked? ldd
mamed gives me (among other libraries):
libSDL-1.2.so.0 => /usr/lib/libSDL-1.2.so.0 (0x40015000)
libSDL_mixer-1.2.so.0 => /usr/lib/libSDL_mixer-1.2.so.0 (0x402d7000)
libSDL_image-1.2.so.0 => /usr/lib/libSDL_image-1.2.so.0 (0x40316000)
libSDL_ttf-2.0.so.0 => /usr/lib/libSDL_ttf-2.0.so.0 (0x4032f000)
which seems to indicate to me that it didn’t link statically. Any thoughts?

Regards,

Pieter HulshoffOn Sunday 14 December 2003 10:23, Bernhard Bliem wrote:

g++ classes.o fileio.o gui.o io.o mamed.o -o mamed sdl-config --static-libs --cflags --libs -lSDL_mixer -lSDL_image -lSDL_ttf

Also add the -static option, and you’ll have to add lots of libraries
to fulfill the linker requirements. Offhand, you’ll need freetype,
zlib, libpng, libjpeg, and probably others depending on the options
the SDL libraries were built with.

See ya,
-Sam Lantinga, Software Engineer, Blizzard Entertainment> On Sunday 14 December 2003 10:23, Bernhard Bliem wrote:

g++ classes.o fileio.o gui.o io.o mamed.o -o mamed sdl-config --static-libs --cflags --libs -lSDL_mixer -lSDL_image -lSDL_ttf

Hmm, it compiles, but how can I tell if it’s actually statically linked? ldd
mamed gives me (among other libraries):
libSDL-1.2.so.0 => /usr/lib/libSDL-1.2.so.0 (0x40015000)
libSDL_mixer-1.2.so.0 => /usr/lib/libSDL_mixer-1.2.so.0 (0x402d7000)
libSDL_image-1.2.so.0 => /usr/lib/libSDL_image-1.2.so.0 (0x40316000)
libSDL_ttf-2.0.so.0 => /usr/lib/libSDL_ttf-2.0.so.0 (0x4032f000)
which seems to indicate to me that it didn’t link statically. Any thoughts?