— Andrew Balmos <SDL_Newsgroup at cox.net> wrote:
Hoi,
I would like to make a library for SDL… (Really
just to make one for
practice than I will make my real one)… But what
needs to be done to call
it a “Library”?
?? Do you mean like an extension library (ala SDL_net,
for example)??
Do I just make a .DLL (Or like for platform) with
function defines and in
the function have it run the right code? Is there
Well, since SDL needs to be portable and all that,
you’d probably just make a source file, from which the
actual library can be built.
much more to this… I
don’t really know if I can make a .dll file for this
type system because it
is not supported (I believe)
If you’re talking about a *nix platform, they have .so
files. Even the crappy computer at my store that I
believe is running SCO OpenServer Unix (or something
like that) supports em. DOS, on the other hand… DOS
is more of a shell than an actual OS :p.
so than what would I
do? Just make a file you
#include?
Not quite… well sort of… #including it isn’t quite
as nice as adding it (it being the source file) to
your project (or adding it into your makefile). Uber
quicky example library bellow, not using SDL…
Thanks,
Andrew
No prob:
– main.c –
#include "mylibrary.h"
int main( void )
{
do_the_chacha();
return 0;
}
– mylibrary.h –
#ifndef MY_LIBRARY
#define MY_LIBRARY
void do_the_chacha( void );
#endif //MY_LIBRARY
– mylibrary.c –
#include “mylibrary.h”
#include <stdio.h>
void do_the_chacha( void )
{
printf(“do the cha-cha!!!\n\r”);
}-----------------
Thus, if using for example microsoft products, to use
this library, you would add mylibrary.c to your
project. You could create a library out of mylibrary.c
so that instead of adding a source file to your
project, you’d be adding a library.
Now, if you’re on a *nix platform, with decently
recent tools, a quicky library compiling example using
gcc…oh yeah and note that mixing ld and gcc when
creating shared libraries is bad for your health and
will leave you with undefined symbols and stuff.
Someone please feel free to add the official stuff
you’re supposed to do with the ‘soname’ and all
that…
step 1: create our (dynamic!) library
gcc -shared -fPIC mylibrary.c -o libmylibrary.so
the -shared flag creates a shared (dynamicly loaded)
library
the -fPIC flag, or the -fpic flag, is required. It
has to do with the memory layout… -fPIC can handle a
larger one, which is why I use it.
step 2: create our test proggy and link it. Note:
libmylibrary.so will need to be where the linker can
find it… try ploping it in /usr/lib
gcc main.c -o main -lmylibrary
step 3: run test proggy
./main
the program should tell you to do the chacha.
step 4: prove it’s really being dynamically linked,
because you don’t trust me
step 4a: change our source for our library
echo ‘#include "mylibrary.c"
void do_the_chacha( void )
{
printf(“Ok, stop cha-cha-ing… you suck.\n\r”);
}’ > mylibrary.c
gcc -shared -fPIC mylibrary.c -o libmylibrary.so
step 4b: make sure to replace the old library with
this new one
step 4c: don’t recompile your test program, but just
run it again.
./main
The program should now insult you.
… now is when you reply and tell me you’re working
on dos, at which point I will say “doh!”
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search
http://shopping.yahoo.com