Recently I decided to move all of our C++/Qt based projects up to the latest version of Qt and C++ toolkits. That means Qt 5, Visual Studio 2015 and all the latest libraries which are needed either for Qt or standalone. There was one caveat tho.. we still need to support Windows XP because a large amount of our player base still uses it. The nightmare begins.
This guide talks about:
-building shared release libraries of OpenSSL with msvc2015 XP target
-build shared release Qt framework with msvc2015 XP target
-build your application with msvc2015 XP target
1. Getting OpenSSL (1.0.1.p)
Building OpenSSL with MSVC 2015 and Windows XP target is an absolute clusterfuck. Forget XP target, even without that it simply WON'T compile with the usual instructions which used to work in the past (ex: http://developer.covenanteyes.com/building-openssl-for-visual-studio/). Thankfully, I found pre-built binaries and a useful batch script at http://www.npcglib.org/~stathis/blog/precompiled-openssl/. The pre-built binaries are ok but they are not built with XP target. They are also built with MT/MD naming which Qt does not really like (Qt insists that you link to libeay32 and ssleay32 and nothing else). Simply renaming them does not really work because .lib tries to include the wrong thing and you end up needing to provide both (no go).
So after a full day of working around the various problems I managed to compile OpenSSL with msvc2015 and XP target. This is a rough procedure so I might have missed something because I recompiled at least 100 times before it worked, but it should at least guide you on the right track:
- Modify the batch script from the link above (you need Cygwin, perl.. ) and make it to a working state
- Run these in cmd: http://doc.qt.io/qt-5/windows-issues.html (make sure you have Windows SDK installed and run the 2015 vcvarsall.bat version of the script, obviously)
- Open ms/ntdll-x86.mk that is generated
- Add the same env vars you just added in cmd to the top of makefile:
123PATH=C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Bin;$(PATH)INCLUDE=C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Include;$(INCLUDE)LIB=C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Include;$(LIB)
1-I"C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Include" -I"C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Include"
- Replace /subsystem flag in LFLAGS with /subsystem:console,5.01
- Also add the same subsystem flag to MKLIB and MKFLAGS
- Remove MD from SSL and CRYPTO flags so you get libeay32 and libssl32 named binaries
- In root OpenSSL folder run:
1nmake -f ms/ntdll-x86.mak
This should produce XP targeted OpenSSL libraries. You know they are XP targeted if you open both DLLs in HEX editor and check rows 130-150, somewhere in those rows you need to se 05 00 01 … appear twice. See: http://www.tripleboot.org/?p=423
2. Build Qt with Windows XP support
Setup the environment again: http://doc.qt.io/qt-5/windows-issues.html
Then configure Qt, I personally used:
configure -target xp -release -qmake -opensource -nomake examples -opengl desktop -platform win32-msvc2015 -openssl -I C:\Users\me\git\openssl-1.0.1p-vs2015\include -L C:\Users\me\git\openssl-1.0.1p-vs2015\shared OPENSSL_LIBS="-llibeay32 -lssleay32 -lgdi32"
where -I and -L flags need to point to OpenSSL include files and the libraries you just built in previous step. We are doing a shared build (I used to like it all static but it turns out shipping Qt libraries bundled in the .exe with every single application update is a complete waste of bandwidth and time, at least 10MB every time).
Then build the Qt with: jom
Do not use nmake because jom is much faster!
After Qt builds, add it as a Kit in Qt Creator. You need to specify path to qmake.exe which is in qt-everywhere-opensource-src-5.X.X\qtbase\bin.
4. Configuring your Application Qmake
Now to your actual project. Add this to your qmake (.pro) file:
DEFINES += _ATL_XP_TARGETING
DEFINES += PSAPI_VERSION=1
QMAKE_LFLAGS_WINDOWS = /SUBSYSTEM:WINDOWS,5.01
Second one? Because reasons: http://blogs.msdn.com/b/vcblog/archive/2009/08/27/windows-sdk-v7-0-v7-0a-incompatibility-workaround.aspx
Add all Qt DLL libraries in the same folder as your .exe (from qtbase/lib), depending on the modules, it is usually at least:
QtCore.dll, QtGui.dll, QtNetwork.dll, QtWidgets.dll…
Also do not forget to include "platforms/qwindows.dll" in the same folder as your .exe. You also need to provide ssleay32.dll and libeay32.dll the same way. You might also need to provide msvc C++ redistributable dll files but I usually just instruct users to install the full C++ redistributable package from Microsoft.
And there you have it, Qt 5 with OpenSSL built with MSVC 2015 and with Windows XP support. An absolute mess if you are starting from zero and don't know all the little annoyances but once you do it's a relief.