Newby Guide to Compiling (and Editing) With Code::Blocks

Prior to beginning. Do note that melee.json, ranged.json, instruments.json, and recipes.json are accessible in cataclysm/data/raw folder. Once you compile the game, whatever is in the raw folder will be reloaded by the executable, meaning you will not have to fiddle with itemdefs if your stuff is in any of these four files. This is quite important as compiling takes a long time on older computers and makes the computer slow down to a crawl while it’s at it.

To compile you need two things.

  1. The code itself.
  2. A program to run a special file in said code that instructs the program on how to compile the files.

After acquiring these two things,

  1. You will need to compile it.

[hr]

1a. The source code can be accessed from github. A link is available on the main page of the mode:

1b. Upon clicking theat link, you will be brought to this github page:

1c. Click the ZIP button in the red circle to commence a download of the code.

End of point 1. You more or less have the code.

===============================================================================================

2a. To download codeblocks, go to this site: http://www.codeblocks.org/downloads/26

2b. On that site, choose this installer:

2c. Install the program, let the default settings guide you.

End of point 2. The program is now fully operational.

====================================================================================

Step 3 will compile the files. This means that if you want to make changes to the code or add stuff into it, you need to do it at this point, not after.

====================================================================================

3a. The code is in the zipped format, IE. it is compressed into a single file to allow for easy downloading. You need to unzip it:

I have already extracted the file, the normal-looking file on top is the result of having extracted the file. The selected option in the right-clicked menu is the one you need to hit to get the normal-looking file.

3b. Go into the unzipped file and open this file:

3c. Upon clicking it, this screen will pop up.

3d. To compile, you need to right-click cataclysm on the left bar, and choose build.

===============================================================

When the program finishes, it will look like this:

Note, itemdefs will take a loooooooooooooong time to get through. As you can see (or maybe not depending on the resize), it takes me 35 minutes alone to compile it. Yours should be faster if you are not using a 5 year old unmodified laptop.

To play your modified game, you need to find the folder where the Code::Blocks file was and the executable should be in there.

Cool, it’s good to have a step-by-step guide for people :).

Just a note: we’re steadily chipping away at itypedef.cpp (the massive item definition file). So, default compile times will hopefully be getting better over time, as we move stuff to data files, rather than having it hardcoded in the source.

Thanks very much for this guide. Makes a lot of sense. Easy enough to understand.

Would someone please update this for all the new gettext stuff that’s now required to compile? Specifically which EXACT files are needed? I’ve been banging my head off the wall for weeks now with this and no luck :(. C’mon, I just wanna code again! -sob-

On that note if anybody actually knows a way to get it to work feel free to post here and we’ll update it into the OP. Right now none of the devs are actually using code::blocks AFAIK, so it might take a while to be updated elsewise.

*Note, copypasted this from my reply in this thread

For Code::Blocks Compiling

Here is what I have setup:

  • In Settings>Compiler>Search Directories
    –Compiler:
    –++ C:\GnuWin32\include
    –++ C:\GnuWin32\share\gettext\intl

–Linker:
–++ C:\GnuWin32\lib
–++ C:\Users\Galen\Libraries\GetText\lib

  • In Project>Build options>Linker Settings (Cataclysm)
    – Other Linker Settings:
    "-Wl,-stack,12000000,-subsystem,windows
    -static -lgdi32 -llibintl -llibiconv"

I also have “libiconv2.dll” and “libintl3.dll” in the project’s root directory.

May be a little overkill, but it works and I don’t care for now as long as it works :smiley:

url for “libiconv” installer : http://superb-dca2.dl.sourceforge.net/project/gnuwin32/libiconv/1.9.2-1/libiconv-1.9.2-1.exe
url for “libintl” installer : http://hivelocity.dl.sourceforge.net/project/gnuwin32/libintl/0.14.4/libintl-0.14.4.exe
url for GetText runtime: http://ftp.gnome.org/pub/gnome/binaries/win32/dependencies/gettext-runtime_0.18.1.1-1_win32.zip
url for GetText runtime-dev: http://ftp.gnome.org/pub/gnome/binaries/win32/dependencies/gettext-runtime-dev_0.18.1.1-1_win32.zip

Hope these help :smiley:

I have a bit of a newbie question here…
What exactly is compiling for?
and what does it do?

@Jericoshost: It’s so you can take the source from the github repo and make your own version of the game. It also helps if you want to contribute as you will be able to tweak and test changes easily without flying blind and just hoping what you type will compile. Compiling, specifically, is turning the source code (.cpp and .h files) into the executable to be run. I am sure someone will come around and give a better answer (hoping for it in fact) but for now I hope the explanation works okay :slight_smile:

Ok I think I get it, thanks.

This doesn’t work with Tilesets?

http://smf.cataclysmdda.com/index.php?topic=1807.msg22249#msg22249

THX!! I build my first CDDA with Code::Blocks!! :smiley:

but I found the cdda build from C::B hasn’t the i18n support :frowning: anyone could help me?? many many thx!!!

Very helpful guide, thank you! Only problem is that the GCC 4.7.1 compiler doesn’t work with Cataclysm anymore per https://github.com/CleverRaven/Cataclysm-DDA/issues/12591.

Easily fixable by using a 4.8.x compiler like the one that comes with codeblocks-13.12mingw-setup-TDM-GCC-481.exe at the moment.

Edit: Noooope still getting an error. Guess I’m trying drbig’s guide to getting most recent GCC in COMPILING.md

Hmm. Will muck about with this soon.

One small question. If the source directory I use is my local copy of my Github repository, I’m assuming it will eat it and require I re-download the whole folder again?

EDIT: Nope. Will apparently have to find a working version of GCC, since it didn’t like the one that came with the installer. Is it just me, or does the very CONCEPT of compiling hate me?

I feel like I should note that you can significantly decrease build time by setting the number of precesses the compiler can use for building, to the number of cores your CPU has. I went from 15 minutes clean build time to 3. When going from 1 to 8 cores. :smiley:

To do this; in Code::Blocks, go to Settings->Compiler…->Global compiler settings->build options. Then set the ‘Number of processes for parallel builds’ to the number of cores you have (I have 8).

After tearing my hair out trying to get this working, I will post this guide so you don’t have to too.

The guide is obsolete: the compiler included with code::blocks doesn’t work with the current builds.

To fix this:

Follow the installation instructions above.

Download http://sourceforge.net/projects/mingw-w64/ it’s the updated complier.

install to a sane directory like: C:\MinGw64.

now go to compiler options under settings in Code::Blocks and in the tab ToolChain executables:

Set the complier’s installtion directory to be: C:\MinGw64\mingw32 or C:*insert_installation directory\mingw32

For the next part taken liberally from: http://forums.codeblocks.org/index.php?topic=13016.0

C compiler: gcc.exe
C++ compiler: g++.exe
Linker for dynamic libs: g++.exe
Linker for static libs: ar.exe
Debugger: There isn’t one for MinGW 64-bit yet, clear this and leave it blank
Resource compiler: windres.exe
Make program: mingw32-make.exe(it says make.exe in the post but it doesn’t exist in the version I downloaded).

Then finally under Project/build options/ pre/post build steps take out those pre-build arguments.

This worked for me…

Yay, so I’m not the only one that can’t ever get the official instructions to work. o3o

The official instructions used to work, but then the decision was made to update the compiler requirements to C++11, and replacing the code::blocks version with the latest version of MinGW(8.1) used to work, but the requirements were changed to require gcc(9.1++), and the MinGW project only goes to 8.1.

The information to install a more recent version is scattered across the four corners of the internet. I wonder if we should do an updated post with the more recent information.

Running project pre-build steps
cmd /c git --version || echo 'git' command not found!
'git' is not recognized as an internal or external command,
operable program or batch file.
'git' command not found!
cmd /c for /F "tokens=*" %i in ('git describe --tags --always --dirty') do echo #define VERSION "%i" >  src/version.h
'git' is not recognized as an internal or external command,
operable program or batch file.
Process terminated with status 1 (0 minute(s), 0 second(s))
0 error(s), 0 warning(s) (0 minute(s), 0 second(s))

Here we go again.

It looks like your git install directory is not in your windows PATH.
Figure out the full path to where you installed git, open your computer properties and find the advanced button, look for the PATH variable in the lower part of the screen, edit it and append “;” to the existing path.

I can’t be more specific right now as I’m not on my home system, but that’s what that error means. Just don’t forget the semi-colon between the last entry and .