[SDL] Question re SDLmain Design Concept

Alex Volkov avcp-sdlmail at usa.net
Mon Jun 5 12:20:59 PDT 2006


Doug wrote:

> >There is nothing to stop you statically linking the runtime libs, and 
> >dynamically linking SDL. All you have to do is rebuild SDLmain so that 
> >it also uses the runtime libs statically. The main SDL library will 
> >continue to work just fine without rebuilding.

> This is what I did.  I just rebuild SDLmain to statically link to
> the C runtime library.  As mentioned, I did NOT rebuild SDL.DLL at
> all - it remains unchanged and unmodified.

This is not a very good idea in some cases. Your application, SDLmain and
SDL.DLL should all be using the same copy of the MS C runtime lib, be that
MSVCRT.DLL (or 70, 71, etc) or a static copy. Which is why SDL on Windows
normally links to MSVCRT.DLL.
Usually, you only need this when you, for example, free() memory that was
malloc()'d and returned by the 3rd party library (not necessarily applicable
to SDL), or when you need to manipulate a FILE* object returned by the 3rd
party library. With SDL on Windows, however, there is another consideration:
if you do
  putenv("SDL_VIDEODRIVER=directx");
in your app, and your app links to a static C lib, and you are using SDL.DLL
(which will always link to either MSVCRxx.DLL or its own copy of C lib), SDL
will not see this envvar at all.
I do not have a list of what objects MS C libs maintain internally, but if
the above example is any indication, there are others.

-Alex.






More information about the SDL mailing list