Making a SDL Libary

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 I just make a .DLL (Or like for platform) with function defines and in
the function have it run the right code? Is there 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) so than what would I do? Just make a file you
#include?

Thanks,
Andrew–
Church Punks! Truth Rebellion! Audio A!

— 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

A SDL Add on like SDL_Net…

Thanks,
Andrew
Church Punks! Truth Rebellion! Audio A!

A add ine like SDL_net…
Church Punks! Truth Rebellion! Audio A!> ----- Original Message -----

From: mrickert85@yahoo.com (Michael Rickert)
Newsgroups: gmane.comp.lib.sdl
Sent: Thursday, September 25, 2003 11:04 PM
Subject: Re: Making a SDL Libary…

— 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

Compiling libraries happens differently depending on what platform you’re
using, but the code will be the same for each platform under SDL, since it
does a lot of work for you if you let it. In the header files where you
declare your functions, be sure to have it laid out like this:

#ifndef MYLIBRARY_H /* Prevent multiple inclusion of the same file */
#define MYLIBRARY_H

#include <some_header.h>
#include <another_header.h>
#include <SDL/begin_code.h>

#ifdef __cplusplus /* Declare functions as C linkage, usable from C and c++/
extern “C” {
#endif/
__cplusplus

/* SDL sets DECLSPEC and SDLCALL to what they need to be to create shared
libraries on your specific platform */
DECLSPEC int SDLCALL MyFunction(int value);
DECLSPEC int SDLCALL SecondFunction(int value);

#ifdef __cplusplus/* End of extern “C” block /
}
#endif/
__cplusplus*/

#include <SDL/close_code.h>
#endif/MYLIBRARY_H/

header files for classes are similar:
#ifndef MYCLASSLIB_H /* Prevent multiple inclusion of the same file */
#define MYCLASSLIB_H

#include <some_header.h>
#include <another_header.h>
#include <SDL/begin_code.h>

/* SDL sets DECLSPEC to what it needs to be to create shared class libraries
under your platform */
class DECLSPEC MyClass
{
public:
MyClass();
int DoSomething();
private:
int somevalue;
};

#include <SDL/close_code.h>
#endif/MYCLASSLIB_H/On Friday 26 September 2003 10:24 pm, Andrew Balmos wrote:

A SDL Add on like SDL_Net…

Thanks,
Andrew

Thanks!..

Andrew
Church Punks! Truth Rebellion! Audio A!> ----- Original Message -----

From: tsm@accesscomm.ca (Tyler Montbriand)
Newsgroups: gmane.comp.lib.sdl
Sent: Saturday, September 27, 2003 10:31 AM
Subject: Re: Re: Making a SDL Libary…

On Friday 26 September 2003 10:24 pm, Andrew Balmos wrote:

A SDL Add on like SDL_Net…

Thanks,
Andrew
Compiling libraries happens differently depending on what platform you’re
using, but the code will be the same for each platform under SDL, since it
does a lot of work for you if you let it. In the header files where you
declare your functions, be sure to have it laid out like this:

#ifndef MYLIBRARY_H /* Prevent multiple inclusion of the same file */
#define MYLIBRARY_H

#include <some_header.h>
#include <another_header.h>
#include <SDL/begin_code.h>

#ifdef __cplusplus /* Declare functions as C linkage, usable from C and
c++/
extern “C” {
#endif/
__cplusplus

/* SDL sets DECLSPEC and SDLCALL to what they need to be to create shared
libraries on your specific platform */
DECLSPEC int SDLCALL MyFunction(int value);
DECLSPEC int SDLCALL SecondFunction(int value);

#ifdef __cplusplus/* End of extern “C” block /
}
#endif/
__cplusplus*/

#include <SDL/close_code.h>
#endif/MYLIBRARY_H/

header files for classes are similar:
#ifndef MYCLASSLIB_H /* Prevent multiple inclusion of the same file */
#define MYCLASSLIB_H

#include <some_header.h>
#include <another_header.h>
#include <SDL/begin_code.h>

/* SDL sets DECLSPEC to what it needs to be to create shared class libraries
under your platform */
class DECLSPEC MyClass
{
public:
MyClass();
int DoSomething();
private:
int somevalue;
};

#include <SDL/close_code.h>
#endif/MYCLASSLIB_H/