Compiling dynamic libraries into my C program

Hello all,

I’m writing a game with SDL, and want to be able to run it on a machine without
SDL installed. I gather, that I need to compile it in a special way, but
which…?

Thanks in advance :slight_smile:

-Andreas

buding at daimi.au.dk wrote:

Hello all,

I’m writing a game with SDL, and want to be able to run it on a machine without
SDL installed. I gather, that I need to compile it in a special way, but
which…?

instead of:

ld main.o -o main sdl-config --libs

do:

ld main.o -o main sdl-config --static-libs

IIRC. Keep in my LGPL details with this (need a method to allow
relinking - aka provision of the .o files or open source)> Thanks in advance :slight_smile:

-Andreas


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

Thanks for the quick reply, although my poor skills in linking leaves me baffled
:slight_smile:
Right now, I have a Makefile with the following:

gcc Skvulp.c -L/Users/buding/lib -lSDLmain -lSDL -framework Cocoa -O3 -o Skvulp

  • I compile on a Mac OS X machine… How does your suggestion translate into my
    current gcc command…? Again, thanks in advance!

-Andreas

When you compile you can use the -R runtime linking flag and supply your own library. The idea is that your product will use the supplied and ‘tested’ library, but they can use newer libraries by replacing yours with a link to their own. A company I contract for uses this to allow the user their required flexibility (giving them the ability to shoot themselves in the foot by using their favorite libs) while allowing us to fully test and support specific libraries.
Just one way,
Jason.> -----Original Message-----

From: sdl-bounces+jclark=ccpu.com at libsdl.org [mailto:sdl-
bounces+jclark=ccpu.com at libsdl.org] On Behalf Of buding at daimi.au.dk
Sent: Sunday, November 07, 2004 3:07 AM
To: sdl at libsdl.org
Subject: [SDL] Compiling dynamic libraries into my C program

Hello all,

I’m writing a game with SDL, and want to be able to run it on a machine
without
SDL installed. I gather, that I need to compile it in a special way, but
which…?

Thanks in advance :slight_smile:

-Andreas


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


Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.788 / Virus Database: 533 - Release Date: 11/1/2004


Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.788 / Virus Database: 533 - Release Date: 11/1/2004

buding at daimi.au.dk wrote:

Thanks for the quick reply, although my poor skills in linking leaves me baffled
:slight_smile:
Right now, I have a Makefile with the following:

gcc Skvulp.c -L/Users/buding/lib -lSDLmain -lSDL -framework Cocoa -O3 -o Skvulp

  • I compile on a Mac OS X machine… How does your suggestion translate into my
    current gcc command…? Again, thanks in advance!

-Andreas

Well, I’ve never dealt with Macs for compiling - normally on linux
manually selecting SDLmain and SDL isn’t the “propper” way to do it,
since dependancies arn’t allways automatically linked in - pretty much,
you’d write your line as:

gcc Skvulp.c -L/Users/buding/lib sdl-config --libs --cflags -framework
Cocoa -O3 -o Skvulp

the part with the ``s (that quote is from the same key as the tilda (~)
key) gets run and replaced with the output - so the above line might
turn into something like:

gcc Skvulp.c -L/Users/buding/lib -lSDLmain -lSDL -lpthread -lm -lX11
-I/usr/local/include/SDL -framework Cocoa -O3 -o Skvulp

(the list I believe included even more last time I compiled on linux…
and it resulted with link errors if any were missing…)

This is a bit more portable as well, since assuming the SDL development
tools are properly installed, it should work for any supported
compiler/OS configuration (since the exact flags may vary between systems).

Now, to statically link to SDL (and these other dependancies) one would
use --static-libs instead of --libs. So, try:

gcc Skvulp.c -L/Users/buding/lib sdl-config --static-libs --cflags
-framework Cocoa -O3 -o Skvulp

and see if that works.

-Mike

Hello again… This time good news - everything works!

Thanks to all you - not only for help with this problem, but with teaching me a
valuable lesson regarding linking in general :slight_smile: - it turns out, that the
sdl-config was not in my search-path (duuh), and I didn’t really know how to
message it into doing what I wanted - but that has been fixed… Thanks again!

-Andreas