I was very surprised to see how easy it was to design and code in Qt, especially with Qt Creator. In contrast to that, actually building, compiling and installing Qt (4.8.4) in Windows is unnecessarily complex and any instructions or even notes saying that you need to compile it yourself seem to be missing. It doesn’t even come with a compiler, which is weird since the MinGW build download will only compile with an old MinGW 4.4.1.
The installer does provide you with a link to build the debug libraries but nothing for the release libraries. Note that I have also installed CMake and added it to my PATH but am unsure if this is important to the build. Also note that this instruction list relies on you already having installed Qt 4.8.4 for Windows (mingw). Though this is likely to be very similar for other compilers but you’ll definitely need to make substitions for some of the explicit examples below.
- So to get this done you’ll first need to install MinGW 4.4.1.
As I had installed “Codeblocks 10.05 with MinGW” earlier, it included the compiler’s binaries so I didn’t need to download MingW. Again, if you are getting this, for Qt4 it is imperative that you use MinGW version 4.4.1 (Qt5 claims to support the latest MinGWs but I have not tried it out yet)
- Make sure the the binaries are in your PATH.
The PATH environment variable allows you to execute a program that may not be in your current directory in command prompt.
In my case, I added “C:\Program Files (x86)\Codeblocks\bin\” to my PATH.
In Windows, you can change environment variables in the System Info window. For Windows 7:
- Press the Windows key and Pause/Break. A window will popup.
- Near the left hit “Advanced System Settings”.
- Navigate to the “Advanced” tab.
- Near the bottom click “Environment Variables”. A dialog will popup.
- In the lower half of the dialog, look for PATH (in the “System variables” groupbox)
- Edit and add the path to your MinGW binaries. (Paths are separated by the ; character)
- Save, hit OK and close, etc
Also make sure that no other paths to MinGW binaries come before it. When looking for an executable, the PATH is searched from first entry to last. For example, if you also have installed the latest MinGW binaries and thus if “C:\MinGW\bin\” comes before “C:\Program Files (x86)\Codeblocks\bin\” (or whatever you are using), those in C:\MinGW\bin\ will be executed, which in this case, will give you problems.
- Now the PATH variable will not be updated system wide until you restart your computer.
If you cannot do that, go back and copy the entire PATH (including your additions) from the above steps.
Open up a command prompt, type “PATH = ” then paste the PATH you just copied then hit enter.
To see if it’s working, in any command prompt type “g++ -v”. Check that the version number printed is correct. If it is not, you have the wrong MinGW installed or your PATH order is incorrect. If you get an error saying cannot find the file then your PATH order is definitely incorrect or you somehow did not install all the binaries. If the version number is correct, proceed to the next step.
- Open up a command prompt and navigate to wherever you have installed Qt (e.g. C:\Qt\4.8.4 so “cd C:\Qt\4.8.4″). In the command prompt you may also need to type “C:\” (or whatever drive you have Qt installed on) then hit enter if your command prompt is on a different drive. As a hint, this folder should contain “bin” and “doc” directories amongst others. It should also contain an executable called uninst.exe (or just “uninst” if you’ve hidden file extensions).
- Save and close any Qt Development applications (QT Creator, codeblocks using QT, MSVC using QT, etc).
- Now type “mingw32-make clean”. This will take a while.
- Now type configure -debug-and-release. This will start configure with those options. Note, unlike linux systems where ./configure is usually purely a highly configurable script, this configure is interactive. So follow the instructions that it will display.
- When it’s done configuring, it should now say something like ‘now ready to be built by mingw32-make’.
- Now type “mingw32-make”, hit enter, and go clubbing… because it will take a long time.
Now both your debug and release libraries are built!
If you are using QT Creator, you’ll then need to clean your project and run qmake (all done easily via the QT Creator’s menu bars). As a new user to Qt, I am not entirely certain how it works so the way I did it was to clean while in debug, then run qmake then build and run, followed by doing the same thing for the release. Additionally, I added “CONFIG += build_all” to my .pro file.
I tried to make this as comprehensive as possible but it thus may have overcomplicated things or been made unclear so post comments if you are not sure about anything!
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Singapore.