Compiling the Wolf4SDL Source Code

Tested On

In the years after Ripper's departure from the Wolfenstein 3D Community, various other members have helped contribute to and fix the Wolf4SDL source code. Bugs have been fixed, parts of the program optimized and features added to empower modders.

The current version of Wolf4SDL accepted as the "master branch" by the community is maintained by KS-Presto (Formerly "AryanWolf3D"). This new version utilizes SDL2 and is actively being refined and worked on.

By the end of this guide, you will be successfully compiling Wolf4SDL, and one step closer to making your game idea a reality!

This guide works with the version of Wolf4SDL available on the 6th of August, 2024. Being actively developed, things may change and the guide may need to be updated in future.

In order to start working with the Wolf4SDL source code, you will need a few things:

A development environment

While it is possible to get the source code compiling in different environments, this guide will be working with DevCPP. Specifically, this one (Dev-C++ 5.0 Beta 9.2 (4.9.9.2) with Mingw/GCC 3.4.2). Download and install the program.

The Wolf4SDL Source Code

This is the most important aspect, as without it there's nothing to edit! To download it, go to the link above, then Downloads→Download Repository.

SDL Libraries and other important files

Wolf4SDL utilizes SDL2, and your development environment will need to be able to access specific files to be able to understand the code it is compiling. This download also includes some necessary files to add to the Wolf4SDL source project itself.
A thank you to Wolf3DGuy for sharing the compatible SDL2 library files, and DevCPP project file.

.dll extension files

While these aren't for the development part, you will need to include these two files with your compiled game. Wolf4SDL looks for the extension files in the game directory, as they are needed for it to take advantage of and use SDL2.

The current version of Wolf4SDL uses SDL2. As such, DevCPP will require access to the SDL2 library or it won't understand what it is trying to compile. To that end, we will need to add those files to DevCPP. You will only need to do this once, as future Wolf4SDL projects you make can use this library over and over.

Create a temporary folder on your computer and extract the ExtraFiles.zip you downloaded in the previous step. It should contain the following:

Temporary Folder

Navigate to the folder where you installed DevCPP, and you will see that there are include and lib folders. These are the folders DevCPP looks to for things like universal header files.

DevCPP folders

Inside our temporary folder, open the DevCPP folder. You'll see include and lib folders in there as well, that were shared by Wolf3DGuy. Copy the contents of these two folders into their matching folders in your DevCPP installation.

Extract the Wolf4SDL source code to an empty folder (Say, C:\Projects\MyProject). This is the home of your game in development!

In the temporary folder from the previous step in this guide, there is a Wolf4SDL2.dev file that has been shared by Wolf3DGuy. Copy it into the same folder as your source code. This is the project file that is used to manage the files of your project. It tells DevCPP what files are in your project, as well as some other settings.

Finally, we have three leftover files in our temporary folder; sdl_winmain.c, sdl_wrap.c and sdl_wrap.h. Take these three files and also add them to your source code. These are three files left out of the repository that will be needed to compile without errors.

Once all the files have been moved appropriately (As in, you did everything in both this and the previous step), you can delete the temporary folder.

Now is the time! Open DevCPP. You should be greeted by something that looks as follows:

DevCPP

This is the program you will use -at a minimum- to compile your source code into a executible file. It can also be used to edit the source code itself, though being an older program some elements are clunky.
If you find it frustrating to use DevCPP for the editing itself, you can use a program like Notepad++ to write your code, and use DevCPP just for compiling.

DevCPP is currently empty though, with nothing open. Go to File→Open Project or File, and a window will pop up. Navigate in that window to the directory with your source code, and choose the Wolf4SDL2.dev file that you added earlier.

You might encounter the following warning:

DevCPP Warning

This is just because your directory doesn't have an obj folder in it. You can create one within your source directory, but DevCPP will also automatically do that the first time you successfully compile the source, which we'll do in a few minutes!

If you get an error regarding files missing like sdl_winmain.c, make sure you added them to the source directory in the last step! If you haven't, exit DevCPP without saving changes to the project, then add the three files (sdl_winmain.c, sdl_wrap.c and sdl_wrap.h) to the directory with your source code. Now, when you open DevCPP and the Wolf4SDL2.dev project, those errors should go away.

Now you should see the sidebar full of files - these are the files that make up Wolf4SDL!

DevCPP Project

With that, the foundations are laid. You can now go to Execute→Compile, and if you followed all the steps above, it should now work! You may get prompts regarding the "obj" folder if it doesn't exist, but the first time Wolf4SDL2 successfully compiles DevCPP should create it for you and the warning will go away in future.

Compiled!

In your source directory, you should be able to navigate to the obj folder and see your Wolf4SDL2.exe file inside.

Now, this executible won't work on it's own - you need the two .dll files we linked to in the first step (Linked here again for ease). Take the Wolf4SDL2.exe and these two files, and drop them in the directory with your copy of Wolfenstein 3D. Run the exe, and you should be able to play the game!

Now that you've done that, you can start looking at making actual changes to your source code!

[Build Error] [obj/Wolf4SDL.exe] Error 1

By looking at the "Compile Log", you will also see at the end a line like this: "gcc.exe: Internal error: Aborted (program collect2)"

To solve this:

  1. Navigate to C:\Dev-Cpp\libexec\gcc\mingw32\3.4.2\ (This location may vary slightly depending on where you installed)
  2. Find the file called "collect2.exe" and rename it to "collect2.exe.old" (you can also delete it)
  3. Try to compile again and it will work.

[Linker error] undefined reference to `WinMain@16'

The current version of Wolf4SDL does not come with some needed files - you will need to add the sdl_main.c, sdl_wrap.c and sdl_wrap.h included in the ExtraFiles.zip from the The Tools You'll Need step in the guide.
If you didn't have these files in your directory when you first opened the Wolf4SDL2.dev project in DevCPP, these files won't be automatically be added, and you may have to do so manually. To do this, go to Project->Add to Project in DevCPP, and select and add those files. Make sure to save your project at this point!

Compiler will show "undefined reference to `__cpu_features_init'"

Make sure there is no C:\mingw folder. Otherwise Dev-C++ will mix different versions of MinGW libraries.