2
\$\begingroup\$

I'm starting to learn C++ (I have a very basic programming background) and I have in mind to create an old-school ASCII-looking roguelike. I know it may be easier in Python, but it has to be in C++. I'm using Windows 10.

I want some eye candy beyond basic ASCII, I've seen libtcod 1.5.1 offers a lot of possibilities so I wanted to try it and follow this tutorial. The problem is I'm stuck right at the beginning, because the libtcod demo "samples_cpp.exe" works but not the example code:

#include "libtcod.hpp"

int main()
{
   TCODConsole::initRoot(80, 50, "libtcod C++ tutorial", false);
   while ( !TCODConsole::isWindowClosed() )
   {
       TCODSystem::checkForEvent(TCOD_EVENT_KEY_PRESS, NULL, NULL);
       TCODConsole::root->clear();
       TCODConsole::root->putChar(40, 25, '@');
       TCODConsole::flush();
   }

   return 0;
}

If I launch the .exe compiled with the command:

g++ src/*.cpp -o tuto -Iinclude -Llib -ltcod-mingw -static-libgcc -static-libstdc++ -Wall

by double-click, it opens and closes a window very fast, and if I execute it from the console I get the in-console message:

24 bits font.
key color : 0 0 0
character for ascii code 255 is colored

Any clues of what I'm doing wrong? The project has all the proper .dll and include folder. This should be pretty easy :/

Thanks a million!


UPDATE: Ok, I got some new info, gdb says this:

[New Thread 7468.0x1f24]
[New Thread 7468.0x203c]
[New Thread 7468.0x1bdc]
[New Thread 7468.0x190c]
[New Thread 7468.0x108c]
24 bits font.
key color : 0 0 0
character for ascii code 255 is colored
Using SDL renderer...

Program received signal SIGSEGV, Segmentation fault.
0x65e70d9f in TCODConsole::clear (this=0x1) at src/console.cpp:196
196     src/console.cpp: No such file or directory.

Not sure what that means, the console.cpp file of libtcode at line 196 has the following:

void TCODConsole::clear() {
    TCOD_console_clear(data);
}
\$\endgroup\$
4
  • 1
    \$\begingroup\$ The command you listed isn't for launching the generated .exe, it's for compiling the code. \$\endgroup\$ – Pikalek Sep 21 '16 at 0:54
  • \$\begingroup\$ I know, I mean I compiled the exe with that command. I'll edit to clarify. \$\endgroup\$ – JoePerkins Sep 21 '16 at 10:32
  • 1
    \$\begingroup\$ Have you seen this thread? forums.roguetemple.com/index.php?topic=4239.0 \$\endgroup\$ – Tyyppi_77 Sep 21 '16 at 16:25
  • \$\begingroup\$ I didn't! It seems to be the exact same problem, I'll see if it helps. Thanks! \$\endgroup\$ – JoePerkins Sep 21 '16 at 16:46
1
\$\begingroup\$

Ok, I finally managed to make it work. The problem was I didn't compile libtcod myself, I was using the files found in this zip.

It was pretty useful the information @Tyyppi_77 found in this forum thread:

TCODConsole::clear method is located at line 196 in libtcod version 1.5.1, so the binary (.dll) library must be from 1.5.1 release. However, that release does not include MinGW libraries (libtcod-mingw[-debug]). Yet gdb cannot find src/console.cpp file implying you did not compile those libraries yourself. Which becomes really confusing: where did you get your libtcod-mingw-debug.dll from? Also, "this = 0x1" indicates that TCODConsole::clear has recevied totally wrong object pointer. Usually it happens when you call a method on non-exising object (which should not be the case here) or when linking against a library has gone haywire.

I suggest you delete your current libtcod (and all traces of it) and try to unpack a clean 1.5.2 release. If that will not help, try to build the library as described here: http://doryen.eptalys.net/data/libtcod/doc/1.5.2/html2/compile_libtcod_mingw.html [NOTE: This link is broken] Note that you do not have to use the exact MinGW version mentioned on that page. When you're compiling library yourself you are fine as long as you're using the same version for everything.

In this thread of github I got the idea of using Brogue's dll files, and they worked. But I suppose the best approach is to compile libtcod myself.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.