The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
Put SDL's dlls in one folder
samleo


Joined: 04 Mar 2014
Posts: 37
Location: Brazil
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?
Put SDL's dlls in one folder
Sik


Joined: 26 Nov 2011
Posts: 905
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%28v=vs.85%29.aspx
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Put SDL's dlls in one folder
Jonas Kulla
Guest

2014-11-05 23:31 GMT+01:00 samleo:
Quote:
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
Put SDL's dlls in one folder
Bob Rubbens
Guest

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


2014-11-06 2:41 GMT+01:00 Jonas Kulla:
Quote:
2014-11-05 23:31 GMT+01:00 samleo:


Quote:
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

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Put SDL's dlls in one folder
Jonas Kulla
Guest

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


http://stackoverflow.com/questions/107888/is-there-a-windows-msvc-equivalent-to-the-rpath-linker-flag


In short, no.
mr_tawan


Joined: 13 Jan 2014
Posts: 161
Why would you not want to keep the dlls in the same folder as the executable ? Just curious.
Put SDL's dlls in one folder
Jonny D


Joined: 12 Sep 2009
Posts: 932
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 D




On Thu, Nov 6, 2014 at 5:13 AM, mr_tawan wrote:
Quote:
Why would you not want to keep the dlls in the same folder as the executable ? Just curious.


_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

samleo


Joined: 04 Mar 2014
Posts: 37
Location: Brazil
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?
Put SDL's dlls in one folder
Daniel Gibson
Guest

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:
Quote:
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

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Put SDL's dlls in one folder
Jeffrey Carpenter
Guest

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


_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Put SDL's dlls in one folder
Daniel Gibson
Guest

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

Am 07.11.2014 um 01:14 schrieb Daniel Gibson:
Quote:
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:
Quote:
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

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org



_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Put SDL's dlls in one folder
Jonas Kulla
Guest

2014-11-07 1:22 GMT+01:00 Daniel Gibson:
Quote:
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.
Put SDL's dlls in one folder
Daniel Gibson
Guest

Am 07.11.2014 um 01:46 schrieb Jonas Kulla:
Quote:
2014-11-07 1:22 GMT+01:00 Daniel Gibson
<mailto:>:

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.


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,
Daniel
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Put SDL's dlls in one folder
Andre Leiradella
Guest

On 06/11/2014 22:22, Daniel Gibson wrote:
Quote:
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,

Andre

Quote:

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:
Quote:
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:
Quote:
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

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org



_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org



_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Put SDL's dlls in one folder
Daniel Gibson
Guest

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%28v=vs.85%29.aspx
[2] http://msdn.microsoft.com/en-us/library/yx9zd12s.aspx
[3] http://msdn.microsoft.com/en-us/library/hdx9xk46.aspx
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Put SDL's dlls in one folder
Daniel Gibson
Guest

Am 07.11.2014 um 02:30 schrieb Daniel Gibson:
Quote:
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%28v=vs.85%29.aspx

[2] http://msdn.microsoft.com/en-us/library/yx9zd12s.aspx
[3] http://msdn.microsoft.com/en-us/library/hdx9xk46.aspx

I'd love to hear if this actually worked, so if you try this, please
keep us updated Smile

Cheers,
Daniel
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
samleo


Joined: 04 Mar 2014
Posts: 37
Location: Brazil
Sorry for the delay. So, I'll evaluate all the solutions from this topics, but I don't have any Windows, when I get one, I'll inform in this topic about that.

Thanks for all help.