I have a simple project created in Qt Creator (installed using Qt SDK 1.1.4). It runs just fine from within Qt Creator, but if I then browse to the output directory in Windows and double-click the EXE, I'll get an error like:
The program can't start because QtCored4.dll is missing from your computer.
Try reinstalling the program to fix this problem.
That's obviously because Qt isn't in my PATH (and I don't want it to be, in case I have multiple versions of Qt on my computer), and Qt Creator / qmake didn't copy the Qt DLLs to the project output.
What I would like to do is use qmake to copy the necessary Qt files to the project output directory - wherever it may be. How do I do this?
(I tried creating a custom target in qmake, but I'm not getting too far...)
UPDATE July 19, 2016: Just to clarify, the above post was concerning Qt4. On Qt5, you should instead look into calling windeployqt
. This Qt5 tool will read your binary, determine which Qt5 runtime files you need, and copy them to your binary directory. Also note that it will fix absolute paths in the Qt5::Core library that are specific to your PC - so use of this tool is basically mandatory unless you want to provide a qt.conf
file yourself.
OK, here's an ugly hack:
Here's some of what I don't like about it:
I'll accept another answer if somebody can clean this up a good bit, for example by shortening it and/or addressing some of my concerns, or just finding a better way in general.
Copy Dependencies with windeployqt
or Copy dependencies manually
Referencing: http://doc.qt.io/qt-5/qmake-variable-reference.html#deployment
In case you need to identify prerequisites / dependencies cross-platform, please take a look at CMake's
getPrerequisites()
. It usesdumpbin
,objbin
,ldd
,otool
for the identification of dependencies.Referencing: https://cmake.org/cmake/help/v3.0/module/GetPrerequisites.html
A bit cleaner method, but it will require doing a
make install
after amake
. It will work on Windows, but would need tweaking for other platforms.If qmake is run just for debug, all output will go into ./debug . If it is just for release, all output goes in ./release . If both, then into ./bin .
I did notice that enabling shadow building in QtCreator caused the executable not to end up in the DESTDIR. I'm not quite sure why.
I ran into the same problem and jwernerny's solution helped me a lot. However, I was using Shadow Build on Window 7 and it needed a bit more tweeking.
I also needed to set the
DESTDIR
according to the current configuration.In my case I wanted to copy
*.qml
files, that's how I achieved it:EDIT :
Since I use Shadow Build I need to use
$$OUT_PWD
to get the output folder.