Creating a 64 bit executable with raylib on windows

When I discovered how easy it was to create a 64 bit executable in Linux for windows, I though great, this should help out a mate who is working with me on a project… poor guy is still struggling to escape from the windows eco system…

Anyhow, I looked at a number of different projects that have packaged GCC for windows but found most wanting in one way or another, one even having the somewhat elderly GCC version of 4 (you won’t be compiling raylib with that!) It then struck me that WSL (Windows subsystem for Linux) might be worth a try. I won’t go into detail about actually installing WSL as there are plenty of resources to help you with this (fortunately its not hard, or particularly time consuming). I chose Debian, and the following instructions assume that is what you are using….

Once Debian is installed from the windows “store” (why does that sound so wrong!) you need to update the package database

sudo apt-get update

This will then allow you to install a few packages you need.

sudo apt-get install make
sudo apt-get install mingw-w64-x86-64-dev
sudo apt-get install gcc-mingw-w64-x86-64

When compiling raylib itself, its better to use the Makefile provided rather than attempting extra complications like cmake

cd raylib/src
make OS=Windows_NT CC=x86_64-w64-mingw32-gcc AR=x86_64-w64-mingw32-ar

Don’t forget when creating or modifying your own Makefile for your project, there are a few different libraries you need to link to, using a single variable in your Makefile keeps things consistent.

 LDFLAGS:=-L../raylib/src -lm -lraylib -pthread -lopengl32 -lgdi32 -lwinmm -mwindows

-mwindows will compile a “gui” app so you don’t get a separate console window as well as you main window, if a user click apps icon from exploder explorer. You might need to change the library path for raylib (-L..raylib/src) if you’ve put it somewhere else…

I’ve found it convenient to keep my normal project Makefile untouched, and put a separate in place for windows users…

make -f

will then use this Makefile rather than the default one.

As well as getting a reasonably up to date version of GCC another advantage is that upgrading it is as easy as

sudo apt-get update
sudo apt-get upgrade

Obviously there are a number of different ways to do this, but the advantages of having a Linux command line as part of your development tool kit shouldn’t be overlooked…

Here it is in action….

Leave a Reply

Your email address will not be published.