SDL_LoadFunction and SDL_LoadObject


I’m a beginner with SDL. I want to use an shared lib in linux, which was loaded
with SDL_LoadObject. I could load/open the lib. But if want load a function with
SDL_LoadFunction(), i didn’t get a function pointer back.

  • My Lib:

#include <stdio.h>
#include <stdlib.h>

void libtest(){


comiled an linked with:
gcc -c -fPIC test.cpp
g++ -shared -Bdynamic test.o -o ./Debug/ -lc

  • Use in my Prog:

#include <SDL/SDL.h>

static struct {
int loaded;
void *handle;
void (*libtest) ();
} lib;

void test(){

if ( lib.loaded == 0 ) {
lib.handle = SDL_LoadObject(Testlib);
if ( lib.handle == NULL ) {
return -1;
lib.libtest = (void (*) ())SDL_LoadFunction(lib.handle, “libtest”);
if ( lib.libtest == NULL ) {
return -1; <---- Hi jumps always in the tree.
return 0;


Thanks for your help.


Sven G??ner wrote:

  • My Lib:

comiled an linked with:
gcc -c -fPIC test.cpp
g++ -shared -Bdynamic test.o -o ./Debug/ -lc

compile libs with gcc and not g++, as g++ mangles the function names, or
enclose the function in ‘extern “C” { … }’.


ThX, the extern “C” declaration has solved the Prob.
(I’m using now gcc, too)