project-ely/docs/setup/setup-windows.md

6.5 KiB

Go with raylib on Windows

Windows is a bit of a different beast when it comes to setting up a development environment. Hopefully this documentation helps get you started. This guide tries to detail everything you would need to download and configure to get this to work.

I originally wrote this documentation back when we were using SDL for development rather than raylib. I left the SDL install instructions because they might be helpful for future projects, and the set up on Windows is particularly weird. For the new raylib version, you still need to set up GCC, but you do not need to install SDL.

As a side note, there is a cool tool called Scoop that you could use to install a lot of these tools. However, I ran into an issue using the Scoop versions of SDL2 because the directory names were different from what the header files were expecting. Below I just installed everything manually instead.

Install Git

If you don't have Git yet, you can download it here. https://git-scm.com/

Run through the installer like normal. There are a lot of config options in the installer, and most of the defaults will work fine. You can change them later in your .gitconfig file if needed.

Download the project

You can now use Git to clone the project.

IDE

Some IDEs like VSCode can clone a Git repository inside of them. You might be able to use that if it's easier.

Git Bash

You can use the Git Bash terminal to do this too. Open up Git Bash. This is a Bash terminal configured to work with Git. Go into some directory where you want to keep your coding projects, and then run the following command.

mkdir projects
cd projects
git clone ssh://git@git.wisellama.rocks:222/Project-Ely/project-ely.git

Install Go

We need the Go compiler. Download it and run through the installer like normal. https://go.dev/

Install GCC

GCC is a C compiler (well technically a the GNU Compiler Collection, but we want it for the C compiler part). Go needs GCC's C compiler so that it can compile the low-level code for the SDL libraries.

GCC on Windows is a bit of a special thing. We'll want to install Mingw-64 which is the Windows port of GCC. https://www.mingw-w64.org/downloads/

You will want to download the "x86_64 win32 seh" version such as this one (ideally the latest version available, just providing a full link as an example). https://github.com/niXman/mingw-builds-binaries/releases/download/12.2.0-rt_v10-rev0/x86_64-12.2.0-release-win32-seh-rt_v10-rev0.7z

There is no installer for this, so we just need to put this in a folder that we'll remember. Something like C:\Users\Username\GCC. Extract the 7z file using 7zip (https://www.7-zip.org/) and then move the directory into that GCC folder we created.

Later on, we will need to set up the environment variables so that other software knows where we installed GCC.

Install SDL2

Download the "devel mingw" versions of the following SDL2 releases (again, ideally the latest versions, just providing links for examples).

Extract the zip files (you can use 7zip or the built-in Windows zip tool) to get a directory for each. They should look something like SDL2_ttf-2.20.1.

Then put these all in some folder you will remember, something like C:\Users\Username\SDL2.

You should end up with 4 folders inside the SDL2 folder you created, one for each of the things we downloaded.

Set environment variables

Now that we have all the software downloaded, we need to set some environment variables so that everything will know where we installed the software.

Go to start menu, search for "env", and select "edit the system environment variables", and hit the Environment Variables... button in the bottom right.

Set the following env variables (change the username directory to match your username as needed).

First we need to set GCC as our default C compiler:

CC = gcc

Then we need to enable CGO (allowing the Go compiler to use a C compiler too):

CGO_ENABLED = 1

Then we need to set our "include" path. This is all of the directories that contain C header files to be included in our code. We need this to include the default GCC include directory as well as each of the SDL2 library include directories that we downloaded. This might be easier to copy-paste yourself if the versions are different. Also, change the Username to match your actual username (use search-replace to make this easier).

C_INCLUDE_PATH = C:\Users\Username\GCC\x86_64-12.1.0-release-win32-seh-rt_v10-rev3\mingw64\include;C:\Users\Username\SDL2\SDL2_image-2.6.2\x86_64-w64-mingw32\include;C:\Users\Username\SDL2\SDL2_mixer-2.6.2\x86_64-w64-mingw32\include;C:\Users\Username\SDL2\SDL2_ttf-2.20.1\x86_64-w64-mingw32\include;C:\Users\Username\SDL2\SDL2-2.24.0\x86_64-w64-mingw32\include;C:\Users\Username\SDL2\SDL2-2.24.0\x86_64-w64-mingw32\include\SDL2;

Then we need to set our "library" path. This is all of the directories that contain compiled library files (on Windows these are *.dll files) that can be imported into our code. This only needs to add all of the SDL2 directories.

LIBRARY_PATH = C:\Users\Username\SDL2\SDL2-2.24.0\x86_64-w64-mingw32\lib;C:\Users\Username\SDL2\SDL2_ttf-2.20.1\x86_64-w64-mingw32\lib;C:\Users\Username\SDL2\SDL2_mixer-2.6.2\x86_64-w64-mingw32\lib;C:\Users\Username\SDL2\SDL2_image-2.6.2\x86_64-w64-mingw32\lib;

And depending on how you installed GCC, you may need to also add its bin directory to your path so that you will be able to call the gcc compiler. There are probably other entries already in your PATH variable, so just add this as an additional entry:

PATH = C:\Users\Username\GCC\x86_64-12.1.0-release-win32-seh-rt_v10-rev3\mingw64\bin

Copy the SDL2 libraries into your code directory

Your code may compile successfully, but it might not run because of the missing SDL2 libraries. Copy each of the *.dll library files into your code directory so that your resulting binary can load them correctly.

The DLL files should be in each of the bin directories of the SDL2 libraries that you downloaded.

Build the software

Now we can just build the software and hope it works!

go build