• Advertisement
Sign in to follow this  

SDL and dlopen()

This topic is 4211 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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 :(

Share this post


Link to post
Share on other sites
Advertisement
Just include all the necessary SDL headers... Structs are effectively memory-layout definitions and don't compile into anything - you _need_ the definition.

Jans.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
thanks, means I can stop wasting time looking for alternative ways.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement