SDL and dlopen()
I have decided to import the SDL library into my project via the dlopen() function, using Linux and g++ compiler.
So I managed to import the function SDL_Init() which initializes the SDL stuff by doing this:
void* handle = dlopen("/usr/lib/libSDL.so", RTLD_LAZY);
typedef void (*SDL_Function)(int);
SDL_Function SDL_Init = (SDL_Function) dlsym(handle, "SDL_Init");
And voila! I can call SDL_Init() with the parameters needed and it all works nicely.
Next step is to load the SDL_Surface struct, which it turns out is more difficult.
I read somewhere that I need to first define my own struct:
struct SDL_Surface {
Uint32 flags; /* Read-only */
SDL_PixelFormat *format; /* Read-only */
int w, h; /* Read-only */
Uint16 pitch; /* Read-only */
void *pixels; /* Read-write */
/* clipping information */
SDL_Rect clip_rect; /* Read-only */
/* Reference count -- used when freeing surface */
int refcount; /* Read-mostly */
} SDL_Surface
Well... that would mean that I have to import SDL_Rect and SDL_PixelFormat before, and those structs require other structs and so on and so on...
Seems to me that there isnt just an easy way of doing something like:
typedef struct SDL_Surface;
and then just point the struct with dlsym()
Please help :(
You can't load types from libraries like that in C, sorry; you'll have to do it manually.
Just include all the necessary SDL headers... Structs are effectively memory-layout definitions and don't compile into anything - you _need_ the definition.
Jans.
Jans.
Quote:
void* handle = dlopen("/usr/lib/libSDL.so", RTLD_LAZY);
typedef void (*SDL_Function)(int);
SDL_Function SDL_Init = (SDL_Function) dlsym(handle, "SDL_Init");
FWIW, SDL_Init returns an int and takes a Uint32 argument. It could cause subtle and hard to track bugs.
Hope this helps.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement