Statically linking to SDL

Ok, say I wanted to statically link to the SDL libraries to build a
Linux i386 binary.

What’s the best way to go about this?

I tried sticking “-static” before the output from ‘sdl-config --libs’,
but when I do that, I get a gazillion xlib errors (probably because my
box only has shared object files for X, right?)

Thx!

-bill!

William Kendrick wrote:

Ok, say I wanted to statically link to the SDL libraries to build a
Linux i386 binary.

What’s the best way to go about this?

I tried sticking “-static” before the output from ‘sdl-config --libs’,
but when I do that, I get a gazillion xlib errors (probably because my
box only has shared object files for X, right?)

“-static” will try to link everything statically. Just put libsdl.a
(with the full path) in the list of objects to link (with the .o). It
might have to go at the beginning or the end, I don’t remember.–
Pierre Phaneuf
Ludus Design, http://ludusdesign.com/

I tried sticking “-static” before the output from ‘sdl-config --libs’,
but when I do that, I get a gazillion xlib errors (probably because my
box only has shared object files for X, right?)

That’s what I found too. My guess is there might be a way to download
the source for XFree86 and make static libraries for the stuff that’s only
shared in the distributions. Of course, the reason it might be shared
only is because it’s enormous. (libXm.so is already 1.3M as a shared
library on my system.)

Paul Braman
@Paul_BramanOn Thu, 27 Jan 2000, William Kendrick wrote:

“-static” will try to link everything statically. Just put libsdl.a
(with the full path) in the list of objects to link (with the .o). It
might have to go at the beginning or the end, I don’t remember.

Hmm… Perhaps, since sdl-config will know more precicly where things are,
a “–static-libs” option would be useful? :slight_smile:

ie, it would do this when you call it with --static-libs:

-l/path_to_lib/libSDL.o

and still do this when you call it with just --libs:

-L/path_to_lib -lSDL

-bill!

I tried sticking “-static” before the output from ‘sdl-config --libs’,
but when I do that, I get a gazillion xlib errors (probably because my
box only has shared object files for X, right?)

That’s what I found too. My guess is there might be a way to download
the source for XFree86 and make static libraries for the stuff that’s only
shared in the distributions. Of course, the reason it might be shared
only is because it’s enormous. (libXm.so is already 1.3M as a shared
library on my system.)

I’d rather just assume the user has X installed (but not necessarily SDL).

:slight_smile:

-bill!> On Thu, 27 Jan 2000, William Kendrick wrote:

If you want to statically link to SDL, you merely link with the ".a"
instead of the “.so”. Your question in the subject would imply you are
not worried about statically linking the XFree86 components, which means
it’s ok if you link to the X “.so” library.–
Brian

I tried sticking “-static” before the output from ‘sdl-config --libs’,
but when I do that, I get a gazillion xlib errors (probably because my
box only has shared object files for X, right?)

That’s what I found too. My guess is there might be a way to download
the source for XFree86 and make static libraries for the stuff that’s only
shared in the distributions. Of course, the reason it might be shared
only is because it’s enormous. (libXm.so is already 1.3M as a shared
library on my system.)

William Kendrick schrieb am 27 Jan 2000:

Ok, say I wanted to statically link to the SDL libraries to build a
Linux i386 binary.

What’s the best way to go about this?

Since you’re doing that on your machine, you don’t need sdl-config.
Just link the needed .a files, e.g.

gcc -o foobar foobar.c /usr/local/lib/libSDL.a

and then dynamically link to all the other libraries libSDL.a links to:

-L/usr/X11R6/lib -lX11 -lXext -lXmu -lXt -lXi -lSM -lICE -ldl -lpthread

Since you’re doing that on your machine, you don’t need sdl-config.
Just link the needed .a files, e.g.

gcc -o foobar foobar.c /usr/local/lib/libSDL.a

Well, I’d like to be able to supply a makefile rule. ie:

make static

:slight_smile:

But, it’s not that important. I can always force people to edit the makefile
if they have any need to statically link it themselves…

Thanks :slight_smile:

-bill!

Since you’re doing that on your machine, you don’t need sdl-config.
Just link the needed .a files, e.g.

gcc -o foobar foobar.c /usr/local/lib/libSDL.a

and then dynamically link to all the other libraries libSDL.a links to:

-L/usr/X11R6/lib -lX11 -lXext -lXmu -lXt -lXi -lSM -lICE -ldl -lpthread

Actually, a simpler solution is to use sdl-config just like you normally
do. Simply go to the directory where the libSDL.so and libSDL.a libraries
are kept (they are normally the same directory) and move libSDL.so to some
garbage name before you do your normal compile.

The linker will attempt to locate libSDL.so if -lSDL is on the command
line (via sdl-config) but it will use libSDL.a if all else fails.

Of course, be sure to move the library back once you’re done. :slight_smile:

Funny story… (diversion)

I was playing around with this trying to see what I could get statically
linked versus dynamically linked without mucking around with Makefiles and
all. I figured that if someone released an incompatible GNU C library
that other Linux distributions hadn’t made standard yet you could just
rename /lib/libc.so to something else. Well, I did…just to see if I
could get the C library statically linked into a program. Any guesses as
to what happened next?

Paul Braman
@Paul_BramanOn Fri, 28 Jan 2000, Andreas Umbach wrote:

could get the C library statically linked into a program. Any guesses as
to what happened next?

An unusable system, of course :)–
Brian

gcc -o foobar foobar.c /usr/local/lib/libSDL.a

Anybody know the best way to do this when you have, say, multiple DLLs
that you dlopen() that depend on SDL, which is included statically in
your base executable? What happens is that the executable only ends up
with the

I tried -Wl,–whole-archive, but this apparently
causes a segfault in ld.

Any other ways?

m.On Fri, Jan 28, 2000 at 12:36:38AM +0100, Andreas Umbach wrote:


Programmer "I wrote a song about dental floss,
Loki Entertainment Software but did anyone’s teeth get cleaner?"
http://lokigames.com/~briareos/ - Frank Zappa, re: the PMRC

try linking with -rdynamic this causes it to use global symbols in the
executable to resolve references in a dynamically loaded library.

although i could have missunderstood the quesiton entirely or something
(tends to happen alot)

Jess

Michael Vance wrote:> On Fri, Jan 28, 2000 at 12:36:38AM +0100, Andreas Umbach wrote:

gcc -o foobar foobar.c /usr/local/lib/libSDL.a

Anybody know the best way to do this when you have, say, multiple DLLs
that you dlopen() that depend on SDL, which is included statically in
your base executable? What happens is that the executable only ends up
with the

I tried -Wl,–whole-archive, but this apparently
causes a segfault in ld.

Any other ways?

m.


Programmer "I wrote a song about dental floss,
Loki Entertainment Software but did anyone’s teeth get cleaner?"
http://lokigames.com/~briareos/ - Frank Zappa, re: the PMRC

Michael Vance wrote:

gcc -o foobar foobar.c /usr/local/lib/libSDL.a

Anybody know the best way to do this when you have, say, multiple DLLs
that you dlopen() that depend on SDL, which is included statically in
your base executable? What happens is that the executable only ends up
with the

I tried -Wl,–whole-archive, but this apparently
causes a segfault in ld.

Any other ways?

`–export-dynamic’

 When creating a dynamically linked executable, add all symbols to
 the dynamic symbol table.  The dynamic symbol table is the set of
 symbols which are visible from dynamic objects at run time.

 If you do not use this option, the dynamic symbol table will
 normally contain only those symbols which are referenced by some
 dynamic object mentioned in the link.

 If you use `dlopen' to load a dynamic object which needs to refer
 back to the symbols defined by the program, rather than some other
 dynamic object, then you will probably need to use this option when
 linking the program itself.> On Fri, Jan 28, 2000 at 12:36:38AM +0100, Andreas Umbach wrote:


Daniel Vogel My opinions may have changed,
666 @ http://grafzahl.de but not the fact that I am right

Paul Braman wrote:

Since you’re doing that on your machine, you don’t need sdl-config.
Just link the needed .a files, e.g.

gcc -o foobar foobar.c /usr/local/lib/libSDL.a

and then dynamically link to all the other libraries libSDL.a links to:

-L/usr/X11R6/lib -lX11 -lXext -lXmu -lXt -lXi -lSM -lICE -ldl -lpthread

Actually, a simpler solution is to use sdl-config just like you normally
do. Simply go to the directory where the libSDL.so and libSDL.a libraries
are kept (they are normally the same directory) and move libSDL.so to some
garbage name before you do your normal compile.

The linker will attempt to locate libSDL.so if -lSDL is on the command
line (via sdl-config) but it will use libSDL.a if all else fails.

If I may suggest… One way some library do this is name their static
archive libfoo_s.a instead of libfoo.a. So that way, when you want to
statically link, you do -lfoo_s, and you let the linker rummage the path
by itself.–
Pierre Phaneuf
Ludus Design, http://ludusdesign.com/