I've been using SDL2 for development almost since it came out. Long story short, I stumbled upon the SDL dynamic API explanation. I've looked in SDL_Dynapi.c to understand how it works. I get that the jump table can be updated with function pointers to newer versions of the functions, but what I don't get is how one would actually goes about doing that dynamically.

Did I miss a function declaration, is there some specific function to call outside the application? I have no idea how an updated dynapi loads itself.


1 Answer 1


It's pretty straightforward, if not entirely well documented. Reading the source (not sure if the released version differs significantly) tells me that you must export an environment variable SDL_DYNAMIC_API with the name of the .so you want to load. That .so must contain a symbol SDL_DYNAPI_entry with signature: Sint32(SDLCALL*)(Uint32 apiver, void *table, Uint32 tablesize). If the library exists and the symbol exists, it will be loaded and the function called.

A combination of apiver (which is equal to SDL_DYNAPI_VERSION) and tablesize (roughly the number of dynamic functions) can be used to fill in the table at table. The apiver will only change if the ABI changes in a non-compatible way. The tablesize may grow, but hypothetically this is ok: it just means that the SDL library has new dynamic functions that you don't have to care about and you can safely only update the parts of table you already know about. The function should return non-zero on success and zero on failure.

The current code doesn't actually do anything on failure. It just carries on like nothing happened, so essentially SDL will just work like normal.

  • \$\begingroup\$ Thank you so much. With your help, I was able to find the SDL_InitDynamicAPILocked function which actually does that. I must admit I skimmed over it because the named seemed irrelevant; Now I see my wrong. \$\endgroup\$ Oct 21, 2014 at 20:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .