Put SDL's dlls in one folder

I would like to know: is it possible to put the SDL’s dlls in one diferent folder? The folder stays inside the “main folder” of my game and I don’t want many dlls in this folder. So, how can I do that in code?------------------------
My project

This is Windows behavior as far as I know, it’ll look first in the
same directory as the program, and if not it’ll look in the system
files (which you don’t want to touch).

On Windows there’s LoadLibrary, you can use it to load arbitrary DLLs
as you wish:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms684175(v=vs.85).aspx

2014-11-05 23:31 GMT+01:00 samleo <samuel.leonardo19 at gmail.com>:

I would like to know: is it possible to put the SDL’s dlls in one
diferent folder? The folder stays inside the “main folder” of my game and I
don’t want many dlls in this folder. So, how can I do that in code?


My project
http://sourceforge.net/projects/dangeroustux/

Personally i am not familiar with Windows development, but as far as I know
there is no way to embed
a DLL search path in the executable itself. What you could try instead is
have a “launcher.bat” that sets
up the PATH environment variable to point to your dll containing folder and
then start the application.

Reference: http://msdn.microsoft.com/en-us/library/7d83bc18.aspx

Isn’t this doable by tinkering with RPATH?

2014-11-06 2:41 GMT+01:00 Jonas Kulla :> 2014-11-05 23:31 GMT+01:00 samleo <samuel.leonardo19 at gmail.com>:

I would like to know: is it possible to put the SDL’s dlls in one
diferent folder? The folder stays inside the “main folder” of my game and I
don’t want many dlls in this folder. So, how can I do that in code?


My project
http://sourceforge.net/projects/dangeroustux/

Personally i am not familiar with Windows development, but as far as I
know there is no way to embed
a DLL search path in the executable itself. What you could try instead is
have a “launcher.bat” that sets
up the PATH environment variable to point to your dll containing folder
and then start the application.

Reference: http://msdn.microsoft.com/en-us/library/7d83bc18.aspx


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

2014-11-06 2:45 GMT+01:00 Bob Rubbens :

Isn’t this doable by tinkering with RPATH?
http://stackoverflow.com/questions/13769141/can-i-change-rpath-in-an-already-compiled-binary

In short, no.

Why would you not want to keep the dlls in the same folder as the executable ? Just curious.

There are plenty of reasons to do so, but consider this one:
You have multiple executables (e.g. for different architectures) that
depend on identically-named dlls and you want one bin directory.

Jonny DOn Thu, Nov 6, 2014 at 5:13 AM, mr_tawan <mr_tawan at hotmail.com> wrote:

Why would you not want to keep the dlls in the same folder as the
executable ? Just curious.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

I want to organize the dlls in one folder just for don’t appears so ugly. In the main folder should stay the executable and inside a dll’s folder.
Well, I’ll evaluable all the answers here. But one last question: is it possible to use the putenv() to change the path and run the game with the dlls in separate folder? Change in runtime the PATH to load the dlls. Or, isn’t possible?------------------------
My project

I’m not sure about this, but if you link against those dlls (and don’t
dynamically load them with LoadLibrary()), I think that they’re resolved
when you start the executable, so setting the PATH ENV var in your
program is probably too late.

If you wanna use LoadLibrary() and GetProcAddress() after all (the
latter would have to be called for every function of any dll you wanna
use… so it’s quite painful compared to just linking against the dll),
you could probably use AddDllDirectory() instead of putenv().

Cheers,
DanielAm 07.11.2014 um 00:59 schrieb samleo:

I want to organize the dlls in one folder just for don’t appears so
ugly. In the main folder should stay the executable and inside a dll’s
folder.
Well, I’ll evaluable all the answers here. But one last question: is it
possible to use the putenv() to change the path and run the game with
the dlls in separate folder? Change in runtime the PATH to load the
dlls. Or, isn’t possible?


My project
http://sourceforge.net/projects/dangeroustux/


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Daniel beat me to it, but yes I have always been under the impression in regards to trying to simply change the PATH during run-time – they are resolved before you have the chance to do anything, so you would indeed have to refer to the use of LoadLibrary & friends.

This is why the alternative that refers to using a batch file or such is able to work – you are able to set the proper environment ahead of time.

Cheers,
Jeffrey Carpenter
<@Jeffrey_Carpenter>

Uh, I just had an ugly idea:
Could it be possible to call putenv() with the modified path and then
one of the many _exec*() functions
(http://msdn.microsoft.com/en-us/library/431x4c1w.aspx) on the
executable itself so it gets executed again, but with modified PATH
variable?
(One should of course first check if the PATH variable was already
modified before calling _exec(), otherwise this is just an endless loop).

Not sure if this works, does anyone with more win32 programming
experience have any thoughts on this?

Cheers,
DanielAm 07.11.2014 um 01:14 schrieb Daniel Gibson:

I’m not sure about this, but if you link against those dlls (and don’t
dynamically load them with LoadLibrary()), I think that they’re resolved
when you start the executable, so setting the PATH ENV var in your
program is probably too late.

If you wanna use LoadLibrary() and GetProcAddress() after all (the
latter would have to be called for every function of any dll you wanna
use… so it’s quite painful compared to just linking against the dll),
you could probably use AddDllDirectory() instead of putenv().

Cheers,
Daniel

Am 07.11.2014 um 00:59 schrieb samleo:

I want to organize the dlls in one folder just for don’t appears so
ugly. In the main folder should stay the executable and inside a dll’s
folder.
Well, I’ll evaluable all the answers here. But one last question: is it
possible to use the putenv() to change the path and run the game with
the dlls in separate folder? Change in runtime the PATH to load the
dlls. Or, isn’t possible?


My project
http://sourceforge.net/projects/dangeroustux/


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

2014-11-07 1:22 GMT+01:00 Daniel Gibson :

Uh, I just had an ugly idea:
Could it be possible to call putenv() with the modified path and then one
of the many _exec*() functions (http://msdn.microsoft.com/en-
us/library/431x4c1w.aspx) on the executable itself so it gets executed
again, but with modified PATH variable?
(One should of course first check if the PATH variable was already
modified before calling _exec(), otherwise this is just an endless loop).

Not sure if this works, does anyone with more win32 programming experience
have any thoughts on this?

Cheers,
Daniel

This would hardly work. The dynamic linker has to resolve all references
before it even
transfers control to main, so it would complain about missing dll’s the
first time it’s run.

Oh, right, I somehow didn’t think this through, ignoring that no matter
if the executable is called the first or second time the dlls are
resolved before the first line of code is executed… (unless there is a
way to tell the windows dynamic linker to ignore those kind of errors,
or at least not terminate immediately?)

So I guess you’ll have to use a batch script (or wrapper executable that
just calls another executable in the dll dir).

Cheers,
DanielAm 07.11.2014 um 01:46 schrieb Jonas Kulla:

2014-11-07 1:22 GMT+01:00 Daniel Gibson <@Daniel_Gibson
mailto:Daniel_Gibson>:

Uh, I just had an ugly idea:
Could it be possible to call putenv() with the modified path and
then one of the many _exec*() functions
(http://msdn.microsoft.com/en-__us/library/431x4c1w.aspx
<http://msdn.microsoft.com/en-us/library/431x4c1w.aspx>) on the
executable itself so it gets executed again, but with modified PATH
variable?
(One should of course first check if the PATH variable was already
modified before calling _exec(), otherwise this is just an endless
loop).

Not sure if this works, does anyone with more win32 programming
experience have any thoughts on this?

Cheers,
Daniel

This would hardly work. The dynamic linker has to resolve all references
before it even
transfers control to main, so it would complain about missing dll’s the
first time it’s run.

Uh, I just had an ugly idea:
Could it be possible to call putenv() with the modified path and then
one of the many _exec*() functions
(http://msdn.microsoft.com/en-us/library/431x4c1w.aspx) on the
executable itself so it gets executed again, but with modified PATH
variable?
(One should of course first check if the PATH variable was already
modified before calling _exec(), otherwise this is just an endless loop).

I’m not sure if this will work.

  1. Turn your .exe into a .dll (let’s call it main.dll) with only one
    exported function (let’s call it rungame)
  2. Write a .exe which sets the DLL path to where you need to load DLLs
    from, LoadLibrary main.dll, GetProcAddress the rungame function, and call it
  3. Profit?

Cheers,

AndreOn 06/11/2014 22:22, Daniel Gibson wrote:

Not sure if this works, does anyone with more win32 programming
experience have any thoughts on this?

Cheers,
Daniel

Am 07.11.2014 um 01:14 schrieb Daniel Gibson:

I’m not sure about this, but if you link against those dlls (and don’t
dynamically load them with LoadLibrary()), I think that they’re resolved
when you start the executable, so setting the PATH ENV var in your
program is probably too late.

If you wanna use LoadLibrary() and GetProcAddress() after all (the
latter would have to be called for every function of any dll you wanna
use… so it’s quite painful compared to just linking against the dll),
you could probably use AddDllDirectory() instead of putenv().

Cheers,
Daniel

Am 07.11.2014 um 00:59 schrieb samleo:

I want to organize the dlls in one folder just for don’t appears so
ugly. In the main folder should stay the executable and inside a dll’s
folder.
Well, I’ll evaluable all the answers here. But one last question: is it
possible to use the putenv() to change the path and run the game with
the dlls in separate folder? Change in runtime the PATH to load the
dlls. Or, isn’t possible?


My project
http://sourceforge.net/projects/dangeroustux/


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Hmm I wonder if maybe calling AddDllDirectory()[1] at the beginning of
main() (or WinMain()) does work, if one uses the /DELAYEDLOAD[2] (and
maybe /DELAY[3]) linker options.
According to the documentation, with “/DELAYEDLOAD foo.dll” the dll will
be loaded “on the first call by the program to a function in that DLL”,
so one could indeed call AddDllDirectory() before the dll is loaded.

Cheers,
Daniel

[1]
http://msdn.microsoft.com/en-us/library/windows/desktop/hh310513(v=vs.85).aspx
[2] http://msdn.microsoft.com/en-us/library/yx9zd12s.aspx
[3] http://msdn.microsoft.com/en-us/library/hdx9xk46.aspx