For epochs, the secrets of how to correctly compile AO2 was buried in the mind of its creator. After over 12 painstaking hours experimenting, compiling, and pacing around my room aimlessly, I succeeded the rite of passage, and I, too, gained the power to compile AO2 into a single executable of less than 10 MB in size.
I shared this power with great care. But as my involvement in AO2 dwindles and the community yearns for their own clients and their own features, and I look through ZIP files in disgust as dozens of DLLs are strewn all over, I have decided to divulge the secrets of how to compile AO2 statically.
With this powerful guide, you can complete the AO2 rite of passage in three hours or less.
- MSYS2
- Qt Creator (on the installer, select only Qt Creator - don't install any other libraries)
- Git for Windows (make sure to set the option to add
git.exe
to your PATH) - UPX
MSYS2 is like Cygwin, except it does not look like it got abandoned 10 years ago, and it uses Pacman for package management. In short, it gives you a Linux-like environment, which allows you to compile with libraries that are usually only found on Linux. It also allows you to bypass the need to waste 3 hours of your life installing Visual Studio, since you can install GCC using MSYS2.
Run through the installer, and run the MSYS2 shell. There are three different shells, each for one environment: MSYS2, which is for general use; MINGW32, which is for compiling 32-bit programs; and MINGW64, which is for compiling 64-bit programs. We will mostly be using MINGW32, but just to set things up, we will use the MSYS2 shell.
Update MSYS2 to the latest version:
$ pacman -Syu
Follow the instructions. If it tells you to close the shell and reopen it, do so, and do pacman -Syu
again to continue the update.
From now on, I will assume that MSYS2 is installed in C:\msys64
.
Here is the real magic: MSYS2 already has our prebuilt packages, including a static, up-to-date version of Qt! We just need to acquire it, as well as other compile-time dependencies:
$ pacman -S mingw-w64-i686-qt5-static mingw-w64-i686-jasper mingw-w64-i686-openssl mingw-w64-i686-nettle mingw-w64-i686-g++
This will take a while - around 10 to 20 minutes. In the meantime, let's discuss why we used prebuilt packages instead of compiling Qt ourselves.
Most people will suggest you to compile Qt statically yourself. This is because static builds are not supported by the open-source version of Qt - it makes licensing difficult. However, building Qt statically on Windows is only possible thanks to dozens of patches applied to the Qt source code just before compilation, despite supposedly being able to simply grab a copy of the Qt source code and begin compiling from there.
Once everything is installed, let us move on to the next step.
- Open Qt Creator.
- Go to
Tools > Options... > Kits
. - Click
Add
. - Name your kit anything you'd like (
MSYS2 i686
). - Set the compiler.
- Click the
Manage...
button. - Click
Add > MinGW > C
. - Set the path of the compiler to
C:\msys64\mingw32\bin\gcc.exe
. - Click
Add > MinGW > C++
. - Set the path of the compiler to
C:\msys64\mingw32\bin\g++.exe
. - You may need to set the platform codegen and linker flags:
-LC:\msys64\usr\local\lib -IC:\msys64\usr\local\include
- Now go back and set the C and C++ compilers to these new entries.
- Click the
- Set the Qt version.
- Click
Manage...
. - Browse to
C:\msys64\mingw32\qt5-static\bin\qmake.exe
. - Qt Creator will automagically detect the Qt version for you.
- Now go back and set the Qt version.
- Click
- For faster compiles, change the
Environment
flags to beMAKEFLAGS=-j4
.
Open a command prompt somewhere, and do git clone https://github.com/AttorneyOnline/AO2-Client
.
Open AO2-Client/Attorney_Online_remake.pro
. The project will open in Qt Creator.
It will ask you to configure the project. Only check the release configuration - do not enable the debug or profile configurations.
We are almost ready to build. We just need a few more dependencies.
Download the latest build of the libraries.
Extract win32-dynamic/bin/discord-rpc.dll
to the AO2 source folder. You will need to copy this DLL to the output folder as well before running.
The official branch of AO2 no longer uses BASS, but if you still use BASS, you need to download it from http://www.un4seen.com/.
You just need to extract bass.dll
and possibly c/bass.lib
.
Just hit the build button.
Locate the Attorney Online executable and run upx --lzma -9 Attorney_Online_remake.exe
on it. This will reduce it from ~20 MB to ~8 MB.
There are some standards you ought to follow when distributing your new-fangled versions of AO2. Failure to comply with these standards will make me very unhappy.
- Qt is LGPL. Since we are statically linking, we are technically required to provide object code separately so that we can theoretically link another version of Qt against our program.
- INCLUDE THE LICENSE AND A LINK TO SOURCE CODE.
- Set a version that clearly indicates that your build is unofficial. What has recently occurred is that various server owners have taken it upon themselves to create a "2.5.1" independently of each other, so now there are various 2.5.1 clients floating around. When people who inquire about 2.5.1 in the official tech support channel, I have to explain to them that 2.5.1 is not the latest official client version, and that it is unofficial and unsupported. Then when an official version of 2.5.1 is released, now there are three undifferentiated versions of 2.5.1 floating around, and I have to then determine if the client is official or unofficial.
There is a launcher coming soon™. Whenever it does get released, you should also follow its guidelines to add a version to your repository manifest so that your users can automatically update to the new version with one click.
If you successfully produced a small AO2 executable with no Qt DLLs, then congratulations, you have officially passed the AO2 Rite of Passage!
Now, with great power comes great responsibility. Go out and make your custom client and destroy Fanat's protocol or whatever.
Rite of passage written by @oldmud0. This work is licensed under the Creative Commons Attribution 4.0 International License.
DOOM#%