Shared library problem

I’ve run into an odd problem that may have nothing to do with SDL, but
someone else here might have encountered something similar.

I have created a shared library of graphics functions using SDL/OpenGL,
and it works fine when I link it with a test program.

I now want to use it with my real program, which has three threads. To
make life simple I call the graphics master function from the main
thread (i.e. I don’t start a new thread). I find that the execution is
jumping to code that I have not called. I now have the very simple case
where the graphics function is called first thing when from main(), and
an exit() call follows immediately after that. In the graphics function
I write out a message, call the shared library function that initializes
SDL and OpenGL, then return.

When I run this I see the message from the graphics function, but not
debugging messages from the shared library function. Instead I get
messages from a function in the main program that I am not invoking.

This testing version of my real program should only use a single thread,
therefore I presume multi-threading is not an issue. As far as I can
see I’m linking the shared library in just the same way in the graphics
test program and in the program with the bizarre behaviour. It seems
that somehow the entry address for the initialization function is
getting corrupted, and instead of going there the execution jumps to an
unrelated function.

What sort of error gives this sort of behaviour?