Roguelike AoC – part 9

A ninth lesson of roguelike game tutorial is different than the previous ones. It concentrates on dividing one source code file we’ve been working on so far, into smaller chunks.

Make, CodeBlock, IDE and Windows

So far I’ve been using CodeBlock (yes, I know, ugly, stupid and archaic). However, up until now it worked pretty well, at least when it came to compilation and running. When I’ve tried to make my code divided in the exact same way like the author did… let’s say it was not pleasant experience.

To start with – running compiler/linker/make in PowerShell is still not the most pleasant thing to do. Secondly – the syntax of makefile differs a little between Windows and author’s Linux. After something about the whole hour spent trying to figure out what flags to use, and how to setup everything I’ve decided that as I’m not in the hurry to make it work, I can use some more modern approach.

CLion to the rescue

Yep. At work, I’ve been using Intellij IDEA for quite some time. I am very fond of JetBrain’s product, therefore I’ve decided to give it a chance with C. Evaluation version is available to be used for 30 days. That is well beyond the scope of my BareMetalDev Advent of Code project. After installation, I was asked to setup a project. It’s nice to see that by default, not Make is being used as a build tool, but CMake, which is a wrapper around Make (or many other build systems to be exact). I’ve read about it some time ago and with CLion I was able to start using it and have support for that (syntax highlighting, code hints).

I won’t go into the details step by step – it’s not a CMake tutorial. The project itself offers a lot, and there is always a lower layer being used (on my Windows machine it’s still Make). However, what I’ve finally come to use is below file:

cmake_minimum_required(VERSION 3.17)
project(RoguelikeCLion C)


include_directories (include)

add_executable(RoguelikeCLion src/main.c src/player.c src/room.c)

find_library(PDCURSES pdcurses lib)
target_link_libraries(RoguelikeCLion LINK_PUBLIC ${PDCURSES})

In order for the above code to work I had to do a couple of changes. First of all – I’ve followed the convention used by the author. I’ve created src folder for source files and include for headers. What is important – I’ve also copied into this folder curses.h file. Without it the project won’t compile!

Second thing to do was to add lib folder, that hosts my compiled PDCurses library. In the tutorial curses is dynamically linked, but this is on Linux. I didn’t even dream of diving into the topic of libraries on Windows, therefore settled on the static one. Whatever works for the time being.

The third thing to do, was to actually change my SIGNS constants into #define declarations. When I’ve left them in rogue.h file, I got errors stating that the constants are being redeclared – and that was true, as the preprocessor was putting them in several files. What I had to do then is to create them as with define directive, and put them in rogue.h file:

#define WALL_SIGN "#"
#define FLOOR_SIGN "."
#define PLAYER_SIGN "@"
#define DOOR_SIGN "+"
#define EMPTY_SIGN " "

Now I was ready to actually run my app. Unfortunately there was a problem. When I’ve tried to run I got:

LINES value must be >= 2 and <= 226: got 1
initscr(): Unable to create SP

It seems that it is a problem that is known for quite some time. There’s no way (at least not without some strange hacks), to actually run curses-based application directly from CLion. Shame really. The good thing is, that after running the build, in the default CMake folder – cmake-build-debug, a generated EXE file just waits to be run. There’s no problem to just double-click it and have our application run in the system’s terminal! Success at last!


With the separation of the code into different files I will stop posting the whole listing of the project. It would be less easy to follow and read. The only thing I will be putting from now on are just ZALINKUJ.

You Might Also Like

Leave a Reply

Back to top