SFML community forums

Help => General => Topic started by: TraverseBiTree on April 14, 2021, 06:45:30 am

Title: How can I not put the .dll files and the .exe file in the same directory??
Post by: TraverseBiTree on April 14, 2021, 06:45:30 am
When I compile a project linked to the dynamic version of SFML , I must put the SFML DLLs with the same directory with .EXE file .Like this:

(https://i.loli.net/2021/04/14/9Z3ycDIS2s7wYzg.jpg)


But I don't want them in the same directory and I don't want to set environment for these DLLs. How can I do that??

(https://i.loli.net/2021/04/14/DcztSTpymXlsC4f.jpg)    (https://i.loli.net/2021/04/14/GFmZr5CJfoOxvhq.jpg)
Title: Re: How can I not put the .dll files and the .exe file in the same directory??
Post by: Laurent on April 14, 2021, 09:18:00 am
You can't.
Title: Re: How can I not put the .dll files and the .exe file in the same directory??
Post by: kojack on April 14, 2021, 11:03:29 am
The easiest way would be to use a static build of sfml. But you explicitly said the dynamic build so I guess that's not an option.

Otherwise it's tricky to change DLL search.
DLLs are either load time linked (happens automatically on program start, such as with sfml's libs) or run time linked (you have to manually load each library and search for functions inside of it one by one)
Run time linked dlls are specified with a file path, so you can load them from anywhere.
Load time linked dlls have fixed locations that are searched (the system path, the working directory, the directory of the exe, etc).

The path used can be changed using SetDllDirectory, but your main function happens after load time linking.
I think setting your app to delayload the dlls (it's an option in the project's linker settings, it makes dlls not get loaded until the first time a function in them is called) might work with SetDllDirectory, but sfml's graphics library is incompatible with delayload (just tested, something with Color upset the linker), so that doesn't work.
Title: Re: How can I not put the .dll files and the .exe file in the same directory??
Post by: TraverseBiTree on April 14, 2021, 11:21:21 am
Thank you very much. I got it. ;D