[SOLVED] Change default location of QtCore.dll and QtGui.dll

  • Dear Qt developers,

    This is probably going to be a very simple question but yet I cannot find an answer using Google nor the search option here on the forums.

    By default, if I want to run a Qt app I need to have both QtCore.dll and QtGui.dll in the same folder as my .exe file. Is there any way to move those files into let's say a /dll folder and tell my app to look for them inside? I'm guessing it's somewhat linker connected but as I stated - can't find an answer.

    Why do I want to do that? Because in my applications folder I want to have only my executable file and no other files present. It will look nice :-).

    Looking forward to an answer.

    Best regards,


  • Those files need to be in the path. In the same directory as the .exe works very well for that, as it is the first place windows looks so you never end up in version conflicts, but you can also define other places. However, you can AFAIK not do that from within your own program (as you can for plugins), as at that point your program already needs to have found the libraries.

    One option may be a startup script however: a script that basically sets the path to search for libraries to whatever you need it to be, and then starts your application executable itself.

  • Thank you for your answer Andre. Now I'm thinking about a different way of achieving that (I want to be as far as possible to batch files, I want the application to be as OS independent as possible). Please tell me if any of those ways are elegant ;-):

    1. Put my whole application into a library and move it along with Qt's libraries to a different folder. Then write a small program which will load up my library and transfer control to it.

    2. Have 2 separate executables. First one is going to be the main application itself put into the /dll folder and the second one will only start up the previous one and close itself down.

  • If you really want such a solution, I would prefer solution 2. I have sometimes seen such things.
    But solution 1 does not solve the problem, as you have to load the dll then by LoadLibrary which will implicitly try to load the Qt libs. But they are not inside the search path then...

    Regarding the platform independency:

    none of the solutions is works on all platforms.

    Windows loads dll as follows:

    Location of the executable

    current dir

    win32 directory

    search the PATH variable

    Linux uses another aproach

    search directories from env variable: LD_LIBRARY_PATH

    The list of libraries cached in /etc/ld.so.cache.

    /lib, followed by /usr/lib.

  • I think the second one is definitely better. If you go for the first one, then you'll need to at least write another C/C++ application in order to load in the libraries. Using the second option, you need no more than a very simple batch script (in Windows) to launch another application.

    The problem here is that if you need to write another C/C++ application, you might one day need to worry about the libraries needed for that application.

  • On the other hand I could statically link to both Qt libs. This would increase the size of my executable but I would achieve the same thing, right?

    Thank you for the answers!

  • But for linking statically, you have restrictions from the licenses:

    You must use Qt Commercial license, or (AFAIK) make you app GPL.
    LGPL does not allow static linking...

  • The app is only for my master thesis. It's probably not going to be available anywhere ;-). If releasing it under GPL is an option for not breaking any licenses then I can do that without a problem.

  • But I suggest you read the license stuff carefully, I'm not a layer :-)

  • Alright, will do that. Thank you for your help!

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.