Skip to content

Compiling on Windows

Jack Greiner edited this page Apr 19, 2023 · 41 revisions

This is a short guide on how to set up a compiling environment on Windows, and using it to compile Naev. Refer to a recent version of this page for info about older workflows to be retired after Naev 0.8.0 (GNU Autotools builds, 32-bit builds). Note: The GNU Autotools build process can also support a cross-compile destined for Windows. Simply pass --host=x86_64-w64-mingw32 to ./configure and proceed from there.

Setting up your compiling environment

Windows

  • Go to the MSYS2 download page and download the installer. Run this installer and install to the default location.
  • When the installation is complete; you can launch msys2 directly. You can also do this via the start menu, or by running ucrt64.exe in your MSYS2 installation directory.
  • When the command prompt comes up for the first time, you need to install the required packages to build Naev. Simply paste the following into your command prompt (via the right mouse button) and hit enter.

To build, install the following:

pacman -S git tar mingw-w64-ucrt-x86_64-gcc mingw-w64-ucrt-x86_64-dlfcn mingw-w64-ucrt-x86_64-freetype mingw-w64-ucrt-x86_64-glpk mingw-w64-ucrt-x86_64-libvorbis \
mingw-w64-ucrt-x86_64-libwebp mingw-w64-ucrt-x86_64-enet mingw-w64-ucrt-x86_64-libxml2 mingw-w64-ucrt-x86_64-luajit mingw-w64-ucrt-x86_64-mesa mingw-w64-ucrt-x86_64-physfs \
mingw-w64-ucrt-x86_64-meson mingw-w64-ucrt-x86_64-libunibreak mingw-w64-ucrt-x86_64-libbacktrace mingw-w64-ucrt-x86_64-ninja mingw-w64-ucrt-x86_64-nsis mingw-w64-ucrt-x86_64-openal mingw-w64-ucrt-x86_64-glpk \
mingw-w64-ucrt-x86_64-pkg-config mingw-w64-ucrt-x86_64-SDL2 mingw-w64-ucrt-x86_64-SDL2_image mingw-w64-ucrt-x86_64-suitesparse mingw-w64-ucrt-x86_64-python-yaml

When asked to proceed with the installation, press y and hit enter.

Linux

Naev is gaining support for cross-compilation. The setup will depend on your distribution. For example, on Arch Linux, it's smart to use a system mingw-w64-ucrt-suitesparse package, critical not to use a system mingw-w64-luajit package (as of 2020-11-09 they're all broken), expedient to use wine-x64 instead of a complete Wine installation, and reasonable to use a helper like yay to handle installing from the AUR. Thus, the setup could look like

pacman -S git meson lib32-gcc-libs nsis python-pip
yay -S mingw-w64-gcc mingw-w64-pkg-config wine-x64 mingw-w64-openblas-lapack mingw-w64-metis              
# Manually build mingw-w64-gmp from AUR, after correcting the dependency on wine.
yay -S mingw-w64-dlfcn mingw-w64-freetype2-bootstrap mingw-w64-gettext mingw-w64-glpk mingw-w64-libpng mingw-w64-libwebp mingw-w64-libxml2 mingw-w64-openal mingw-w64-sdl2_mixer mingw-w64-suitesparse                                                        

You will also need a cross file for the Meson build. This setup could look like

curl -O --output-dir ~/.local/share/meson/cross/ https://raw.githubusercontent.com/mesonbuild/meson/master/cross/linux-mingw-w64-64bit.txt
$EDITOR ~/.local/share/meson/cross/linux-mingw-w64-64bit.txt

(and update it to match the installed paths, e.g. "sys_root = '/'".)

Building

Begin by starting either environment via the start menu, or by running ucrt64.exe in your MSYS2 installation directory. (On Linux, simply open a terminal.)

Step 1:

Clone the git repo. You can do this by entering:

git clone https://github.com/naev/naev.git <dir>
cd <dir>
git submodule init
git submodule update
git config submodule.recurse true

Where <dir> is the name of the subdirectory to clone into (e.g., "naev").

Step 2:

If you're building on Windows, you should now run

meson setup <build dir> . --prefix=<source dir>/extras/windows/installer --bindir=bin -Dndata_path=bin

where <source dir> is the full path to the directory created on step 1.

If cross-compiling on Linux, you'll need an extra argument:

meson setup <build dir> . --prefix="$(pwd)"/extras/windows/installer --bindir=bin -Dndata_path=bin --cross-file linux-mingw-w64-64bit.txt

You can choose any location for the build directory -- most usefully, outside the source tree, for example "../build-naev". Note: You should only need to do this once. After the first setup, you can update these settings using the meson configure command from the <build dir>.

Step 3:

When ready, just cd into the <build dir> created on step 2, and run

meson compile

If everything went without any errors, you should have a naev.exe in the current directory! However, it probably won't be able to find the DLL files it needs to start.

Building the release installer and zip:

On Windows, the meson install command packages everything (including the required DLL files) into an NSIS installer.

meson install

Running this installer is the easiest way get the compiled game to work without complaining about missing DLL files.