# SDL initialization

**URL:** <https://discourse.libsdl.org/t/sdl-initialization/15467>\
**Category:** SDL Development\
**Created:** [July 15, 2008, 2:21pm UTC](https://discourse.libsdl.org/t/sdl-initialization/15467 "2008-07-15T14:21:19Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Grzegorz\_Tanski](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/g/b19c9b/32.png) [@Grzegorz\_Tanski](https://discourse.libsdl.org/u/Grzegorz_Tanski)\
**Post date:** [July 15, 2008, 2:21pm UTC](https://discourse.libsdl.org/t/sdl-initialization/15467/1 "2008-07-15T14:21:19Z")

</div>

It there a way to dynamically check if there is SDL dynamic library or not?  
Now when I link with SDL it forces existance of SDL.dll (in case of Windows) or  
application does not start at all.

---

<div class="post-metadata">

**Author:** ![William\_Langford](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/w/d6d6ee/32.png) [@William\_Langford](https://discourse.libsdl.org/u/William_Langford)\
**Post date:** [July 15, 2008, 8:44pm UTC](https://discourse.libsdl.org/t/sdl-initialization/15467/2 "2008-07-15T20:44:06Z")

</div>

Its been some years since I’ve done DLL depency on windows without  
linking against them, but I believe you can OpenDLL or something  
similar from within code. This keeps it out of the exe header as a  
dependency, but lets the program attempt to run without it (and if you  
don’t require it then you can use fail checks to disable usage etc).  
I… can’t recall the author of the book I worked from… was a  
win3.1/win32 reference of some kind… was the defacto old win16/win32  
reference as well. Really wish I could recall the guy’s name.

-WillOn Tue, Jul 15, 2008 at 9:21 AM, Grzegorz Tanski wrote:

> It there a way to dynamically check if there is SDL dynamic library or not?  
> Now when I link with SDL it forces existance of SDL.dll (in case of Windows) or  
> application does not start at all.

---

<div class="post-metadata">

**Author:** ![William\_Langford](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/w/d6d6ee/32.png) [@William\_Langford](https://discourse.libsdl.org/u/William_Langford)\
**Post date:** [July 15, 2008, 8:47pm UTC](https://discourse.libsdl.org/t/sdl-initialization/15467/3 "2008-07-15T20:47:49Z")

</div>

I believe LoadLibrary() may be what you’re looking for in the win32 world.

> **[LoadLibraryA function (libloaderapi.h) - Win32 apps](https://learn.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-loadlibrarya?redirectedfrom=MSDN)**
>
> Loads the specified module into the address space of the calling process. (LoadLibraryA)

Note: article also mentions the subsequent calls you’ll need to make  
to access functions and resources within the supplied library.

-WillOn Tue, Jul 15, 2008 at 3:44 PM, Will Langford \<@William\_Langford\> wrote:

> On Tue, Jul 15, 2008 at 9:21 AM, Grzegorz Tanski wrote:
> 
> > It there a way to dynamically check if there is SDL dynamic library or not?  
> > Now when I link with SDL it forces existance of SDL.dll (in case of Windows) or  
> > application does not start at all.

---

<div class="post-metadata">

**Author:** ![Grzegorz\_Tanski](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/g/b19c9b/32.png) [@Grzegorz\_Tanski](https://discourse.libsdl.org/u/Grzegorz_Tanski)\
**Post date:** [July 15, 2008, 9:17pm UTC](https://discourse.libsdl.org/t/sdl-initialization/15467/4 "2008-07-15T21:17:05Z")

</div>

Will Langford \<unfies [gmail.com](http://gmail.com)\> writes:

> > > It there a way to dynamically check if  
> > > there is SDL dynamic library or not?  
> > > Now when I link with SDL it forces  
> > > existance of SDL.dll (in case of Windows) or  
> > > application does not start at all.
> 
> I believe LoadLibrary() may be what you’re looking for in the win32 world.
> 
> [LoadLibraryA function (libloaderapi.h) - Win32 apps | Microsoft Learn](http://msdn.microsoft.com/en-us/library/ms684175(VS.85).aspx)
> 
> Note: article also mentions the subsequent calls you’ll need to make  
> to access functions and resources within the supplied library.
> 
> -Will

Thanks for reply.

LoadLibrary() is a kind of solution, but  
it would be best when SDL\_init() simply  
fails when “SDL.dll” is missing. LoadLibrary()  
forces me to use GetProcAdress() for every  
function I want to use and it not portable  
(when the whole thing to use SDL is portability).  
I wonder how it works on other platforms.  
Must check on Mac and Linux.

---

<div class="post-metadata">

**Author:** ![Brian\_Barrett](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/brian_barrett/32/427_2.png) [@Brian\_Barrett](https://discourse.libsdl.org/u/Brian_Barrett)\
**Post date:** [July 15, 2008, 10:02pm UTC](https://discourse.libsdl.org/t/sdl-initialization/15467/5 "2008-07-15T22:02:11Z")

</div>

How could SDL\_Init return an error - when SDL\_Init is inside SDL.dll =)

There is no easy solution. If you let windows load SDL.dll for you  
then it will refuse to load your application unless it finds it. The  
only other way (AFAIK) is using LoadLibrary() and friends, with the  
downsides that you mentioned.On Tue, Jul 15, 2008 at 10:17 PM, Grzegorz Tanski wrote:

> Will Langford \<unfies [gmail.com](http://gmail.com)\> writes:  
> LoadLibrary() is a kind of solution, but  
> it would be best when SDL\_init() simply  
> fails when “SDL.dll” is missing.

---

<div class="post-metadata">

**Author:** ![Pierre\_Phaneuf](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/pierre_phaneuf/32/94_2.png) [@Pierre\_Phaneuf](https://discourse.libsdl.org/u/Pierre_Phaneuf)\
**Post date:** [July 15, 2008, 10:13pm UTC](https://discourse.libsdl.org/t/sdl-initialization/15467/6 "2008-07-15T22:13:45Z")

</div>

> LoadLibrary() is a kind of solution, but  
> it would be best when SDL\_init() simply  
> fails when “SDL.dll” is missing. LoadLibrary()  
> forces me to use GetProcAdress() for every  
> function I want to use and it not portable  
> (when the whole thing to use SDL is portability).  
> I wonder how it works on other platforms.  
> Must check on Mac and Linux.

What would you do in the case where the library is not available?On Tue, Jul 15, 2008 at 5:17 PM, Grzegorz Tanski wrote:

–

> **[Pierre Phaneuf's Diary](https://pphaneuf.livejournal.com/)**
>
> pphaneuf - the new blog in LiveJournal. There should be new interesting records soon.

---

<div class="post-metadata">

**Author:** ![William\_Langford](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/w/d6d6ee/32.png) [@William\_Langford](https://discourse.libsdl.org/u/William_Langford)\
**Post date:** [July 15, 2008, 10:21pm UTC](https://discourse.libsdl.org/t/sdl-initialization/15467/7 "2008-07-15T22:21:54Z")

</div>

> What would you do in the case where the library is not available?

If you support multiple backends for audio, video, system control, etc  
– then maybe you’d use a different mechanism.

IE: supporting

OpenGL, DirectX, GDI, DirectX, or SDL for video.

waveout, dsound, artsd, etc, sdl for audio

etc etc etc

Kind of going with a utilitarian approach to a generic app. While I  
don’t agree with the approach, it’s definitely feasible.

-Will

---

<div class="post-metadata">

**Author:** ![Pierre\_Phaneuf](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/pierre_phaneuf/32/94_2.png) [@Pierre\_Phaneuf](https://discourse.libsdl.org/u/Pierre_Phaneuf)\
**Post date:** [July 15, 2008, 10:30pm UTC](https://discourse.libsdl.org/t/sdl-initialization/15467/8 "2008-07-15T22:30:42Z")

</div>

> > What would you do in the case where the library is not available?
> 
> If you support multiple backends for audio, video, system control, etc  
> – then maybe you’d use a different mechanism.

My idea there was that not having a portable way to do this is fine,  
in a way, since you’ll almost certainly have to do something  
non-portable as a fallback (although I’d probably have SDL as a  
fallback in the first place, myself).

Me, I just ship the appropriate DLLs in the installer, and link  
against SDL normally.On Tue, Jul 15, 2008 at 6:21 PM, Will Langford wrote:

–

> **[Pierre Phaneuf's Diary](https://pphaneuf.livejournal.com/)**
>
> pphaneuf - the new blog in LiveJournal. There should be new interesting records soon.

---

<div class="post-metadata">

**Author:** ![Julien\_Clement1](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/j/958977/32.png) [@Julien\_Clement1](https://discourse.libsdl.org/u/Julien_Clement1)\
**Post date:** [July 16, 2008, 11:12am UTC](https://discourse.libsdl.org/t/sdl-initialization/15467/9 "2008-07-16T11:12:20Z")

</div>

Pierre,

Do you mean that you incorporate the SDL dynamic lib with the application package, and then  
copy it to a particular location if no other lib is found ? (I suppose most applications with installers  
do it that way isn’t it ?)

Then, loading the library is necessary only when the lib is not installed in a standard location, isn’t it ?

----- Message d’origine ----De : Pierre Phaneuf   
? : A list for developers using the SDL library. (includes SDL-announce)   
Envoy? le : Mercredi, 16 Juillet 2008, 0h30mn 42s  
Objet : Re: [SDL] SDL initialization

On Tue, Jul 15, 2008 at 6:21 PM, Will Langford wrote:

> > What would you do in the case where the library is not available?
> 
> If you support multiple backends for audio, video, system control, etc  
> – then maybe you’d use a different mechanism.

My idea there was that not having a portable way to do this is fine,  
in a way, since you’ll almost certainly have to do something  
non-portable as a fallback (although I’d probably have SDL as a  
fallback in the first place, myself).

Me, I just ship the appropriate DLLs in the installer, and link  
against SDL normally.

–

> **[Pierre Phaneuf's Diary](https://pphaneuf.livejournal.com/)**
>
> pphaneuf - the new blog in LiveJournal. There should be new interesting records soon.

* * *

SDL mailing list  
SDL at [lists.libsdl.org](http://lists.libsdl.org)  
[http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org](http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org)

```
  _____________________________________________________________________________ 

```

Envoyez avec Yahoo! Mail. Une boite mail plus intelligente [http://mail.yahoo.fr](http://mail.yahoo.fr)

---

<div class="post-metadata">

**Author:** ![Pierre\_Phaneuf](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/pierre_phaneuf/32/94_2.png) [@Pierre\_Phaneuf](https://discourse.libsdl.org/u/Pierre_Phaneuf)\
**Post date:** [July 16, 2008, 2:12pm UTC](https://discourse.libsdl.org/t/sdl-initialization/15467/10 "2008-07-16T14:12:14Z")

</div>

> Do you mean that you incorporate the SDL dynamic lib with the application  
> package, and then  
> copy it to a particular location if no other lib is found ? (I suppose most  
> applications with installers  
> do it that way isn’t it ?)
> 
> Then, loading the library is necessary only when the lib is not installed in  
> a standard location, isn’t it ?

On Linux, I do not package SDL, but use the package management.  
Nowadays, people use things like Synaptics or “apt-get install  
mygame”, and everything is figured out for them, it gets SDL  
automatically.

On Windows and Mac OS X, I put the SDL library in the application  
installer, and _never_ use the “system” library, because it’s just  
about never there, or it’s in some non-standard location. On both  
these platforms, there’s a particular place where you can put  
libraries alongside the application and they will be found (on  
Windows, the directory where the EXE is located is at the front of the  
DLL path, and on Mac OS X, you can put internal frameworks inside an  
application bundle).On Wed, Jul 16, 2008 at 7:12 AM, julien CLEMENT wrote:

–

> **[Pierre Phaneuf's Diary](https://pphaneuf.livejournal.com/)**
>
> pphaneuf - the new blog in LiveJournal. There should be new interesting records soon.

---

<div class="post-metadata">

**Author:** ![Grzegorz\_Tanski](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/g/b19c9b/32.png) [@Grzegorz\_Tanski](https://discourse.libsdl.org/u/Grzegorz_Tanski)\
**Post date:** [July 16, 2008, 2:33pm UTC](https://discourse.libsdl.org/t/sdl-initialization/15467/11 "2008-07-16T14:33:06Z")

</div>

Brian \<brian.ripoff [gmail.com](http://gmail.com)\> writes:

> How could SDL\_Init return an error - when SDL\_Init is inside SDL.dll =)

🙂 , but to be serious, simply SDL\_Init should be placed in SDL.lib instead of  
SDL.dll and it should try to open .dll and if its ok call SDL\_init from .dll or  
return error code when there is no .dll.

---

<div class="post-metadata">

**Author:** ![Grzegorz\_Tanski](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/g/b19c9b/32.png) [@Grzegorz\_Tanski](https://discourse.libsdl.org/u/Grzegorz_Tanski)\
**Post date:** [July 16, 2008, 2:36pm UTC](https://discourse.libsdl.org/t/sdl-initialization/15467/12 "2008-07-16T14:36:20Z")

</div>

> What would you do in the case where the library is not available?

My app runs fine fired from console, but its nice when it have graphical preview  
window. So scenario is simple. Try to open SDL, if ok show user graphics,  
otherwise work in text mode.

---

<div class="post-metadata">

**Author:** ![Jeroen\_Clarysse](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/j/b9e5f3/32.png) [@Jeroen\_Clarysse](https://discourse.libsdl.org/u/Jeroen_Clarysse)\
**Post date:** [July 16, 2008, 5:18pm UTC](https://discourse.libsdl.org/t/sdl-initialization/15467/13 "2008-07-16T17:18:45Z")

</div>

can anyone confirm or deny if 1.3 has dual monitor support on both  
Windows AND Mac OS X ?

i have a project that i’m about to rewrite (partially) from DirectX to  
SDL, but I can only do it if I have multimon support…

feedback GREATLY appreciated since I have to convince my boss to go  
with SDL !

---

<div class="post-metadata">

**Author:** ![matt\_hull](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/m/aeb1de/32.png) [@matt\_hull](https://discourse.libsdl.org/u/matt_hull)\
**Post date:** [July 16, 2008, 6:04pm UTC](https://discourse.libsdl.org/t/sdl-initialization/15467/14 "2008-07-16T18:04:33Z")

</div>

you could at least do opengl, anything but directx :SOn Wed, 16 Jul 2008, jeroen clarysse wrote:

> can anyone confirm or deny if 1.3 has dual monitor support on both Windows  
> AND Mac OS X ?
> 
> i have a project that i’m about to rewrite (partially) from DirectX to SDL,  
> but I can only do it if I have multimon support…
> 
> feedback GREATLY appreciated since I have to convince my boss to go with SDL  
> !
> 
> * * *
> 
> SDL mailing list  
> SDL at [lists.libsdl.org](http://lists.libsdl.org)  
> [http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org](http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org)

---

<div class="post-metadata">

**Author:** ![Jeroen\_Clarysse](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/j/b9e5f3/32.png) [@Jeroen\_Clarysse](https://discourse.libsdl.org/u/Jeroen_Clarysse)\
**Post date:** [July 16, 2008, 6:10pm UTC](https://discourse.libsdl.org/t/sdl-initialization/15467/15 "2008-07-16T18:10:17Z")

</div>

with directX, I have sufficient code to work multimon. If I can’t get  
multimon with SDL on mac & windows, there is little or no use in SDL,  
since I only need 2D blitting and some sound

but I like SDL so much (used it for my previous project that did not  
need multimon) that i REALLY want to use it again

so all will depend on wether SDL 1.3 supports multimon or not on mac  
AND windows\> you could at least do opengl, anything but directx :S

> On Wed, 16 Jul 2008, jeroen clarysse wrote:
> 
> > can anyone confirm or deny if 1.3 has dual monitor support on both  
> > Windows AND Mac OS X ?
> > 
> > i have a project that i’m about to rewrite (partially) from DirectX  
> > to SDL, but I can only do it if I have multimon support…
> > 
> > feedback GREATLY appreciated since I have to convince my boss to go  
> > with SDL !
> > 
> > * * *
> > 
> > SDL mailing list  
> > SDL at [lists.libsdl.org](http://lists.libsdl.org)  
> > [http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org](http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org)
> 
> * * *
> 
> SDL mailing list  
> SDL at [lists.libsdl.org](http://lists.libsdl.org)  
> [http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org](http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org)
