Author Topic: BearLibTerminal: a pseudo-terminal window library for roguelike  (Read 282551 times)

Tooth

  • Newcomer
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Re: BearLibTerminal: a pseudo-terminal window library for roguelike
« Reply #45 on: July 12, 2015, 08:32:00 PM »
I don't know if this is exactly the right place to post this, but there aren't any other BearLibTerminal forums as far as I can tell, so might as well. I seem to be having some issues with this library. I created a small main.cpp that just opens and closes the terminal to make sure the library works, but when I try to link it with the library, I keep getting "undefined reference to '_imp__terminal_open()' and '_imp__terminal_close()'". I think the prefix is just name mangling, so I'm not concerned with that, but whatever I do, I can't get the linker to find definitions for the functions. The command I used was "g++ main.cpp -L. -I. BearLibTerminal -lBearlibTerminal -o main" along with several variants of that which changed orders, added extra -l s or .lib s  or almost anything else. Everything gives the same error. Also of note, I am using Mingw64 with the MSYS2 shell, if that's at all relevant. Any help with this would be great, as I'm really excited about BearLibTerminal and want to use it if at all possible.

Cfyz

  • Rogueliker
  • ***
  • Posts: 194
  • Karma: +0/-0
    • View Profile
    • Email
Re: BearLibTerminal: a pseudo-terminal window library for roguelike
« Reply #46 on: July 12, 2015, 09:42:09 PM »
Yes, this is the right place, the amount of discussion/issues does not justify a dedicated forum (hmm, yet?). On another thought, issues should go to issue tracker of the repository. Always forget there is one.

The problem with linking is that MinGW linker does not seem to understand Windows import libraries (the .lib accompanying .dll, usual for MSVC), but it considers such library first while searching. So it finds BearLibTerminal.lib, tries to link against it and complains there is still no implementation. MinGW, however, is fully capable to link against .dll, so you just need to remove the .lib file. The working command is pretty much what you've used:
Code: [Select]
g++ -I. main.cpp -L. -lBearLibTerminal -o main
Noted this down, such nuances really should be documented =_=.
« Last Edit: July 12, 2015, 09:57:07 PM by Cfyz »

Tooth

  • Newcomer
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Re: BearLibTerminal: a pseudo-terminal window library for roguelike
« Reply #47 on: July 12, 2015, 10:29:12 PM »
Hmm...
I tried that command. It now says "./BearLibTerminal.dll: file format not recognized." I also tried it on another MinGW(normal, not 64) shell and a Cygwin shell that I had lying around, and both did the same thing. I thought DLLs were pretty much the standard for windows external libraries, so I don't really understand how this could be the case. Are my toolchains set up incorrectly?

Cfyz

  • Rogueliker
  • ***
  • Posts: 194
  • Karma: +0/-0
    • View Profile
    • Email
Re: BearLibTerminal: a pseudo-terminal window library for roguelike
« Reply #48 on: July 12, 2015, 10:50:19 PM »
This most likely means compiler and library do have different bitness. It sometimes not obvious: rare compiler build shows what its available/target bitnesses are. Requesting the mode manually usually helps identify the problem.

For example, using 32-bit TDM-GCC and 64-bit .dll:
Code: [Select]
g++ main.cpp -L. -lBearLibTerminal -o main
./BearLibTerminal.dll: file not recognized: File format not recognized
collect2.exe: error: ld returned 1 exit status
Now explicitly specifying I want it to be 64-bit (to match the library):
Code: [Select]
g++ -m64 main.cpp -L. -lBearLibTerminal -o main
main.cpp:1:0: sorry, unimplemented: 64-bit mode not compiled in
Now replacing the library with 32-bit version does help.

Btw, MSYS/Cygwin are unnecessary here as BearLibTerminal.dll is a regular Windows library.

Tooth

  • Newcomer
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Re: BearLibTerminal: a pseudo-terminal window library for roguelike
« Reply #49 on: July 12, 2015, 11:18:29 PM »
Ah! That's done it!
32bit version of the library works for me. It's weird though that MinGW64 didn't work with a 64bit library though...
In any case, thank you so much Cfyz! Now to make a game!

Xangi

  • Newcomer
  • Posts: 4
  • Karma: +0/-0
    • View Profile
Re: BearLibTerminal: a pseudo-terminal window library for roguelike
« Reply #50 on: July 29, 2015, 07:23:13 AM »
So, trying to use this in VS2012 for C# I'm getting this http://puu.sh/jh89p/d6c2d8767b.png
When I looked up what to do I found that I had to run some kind of tool, which I tried and got this http://puu.sh/jh8bD/5518b8ff84.png

Not sure what's going on, but apparently it's because this wasn't compiled with .NET?

EDIT: I also tried just adding the DLL, same error I was getting before. It can't find the DLL to actually use it so it crashes at runtime.
« Last Edit: July 29, 2015, 07:27:03 AM by Xangi »

Cfyz

  • Rogueliker
  • ***
  • Posts: 194
  • Karma: +0/-0
    • View Profile
    • Email
Re: BearLibTerminal: a pseudo-terminal window library for roguelike
« Reply #51 on: July 29, 2015, 08:18:58 AM »
You do not need to reference the library binary in any way. The .dll piece is pure native code with plain C interface. However, you will obviously need to place it in 'working directory' of the application (usually just besides the application executable; this is true for VS2015 at least, not sure about other VSs and it may be overrided in project settings).

The .\Include\C#\BearLibTerminal.cs file is the one that needed to be included in the project (there is a bunch of DllImports in there). You will also need System.Drawing assembly referenced.


Xangi

  • Newcomer
  • Posts: 4
  • Karma: +0/-0
    • View Profile
Re: BearLibTerminal: a pseudo-terminal window library for roguelike
« Reply #52 on: July 29, 2015, 08:28:23 AM »
So I did all of that and it works now, but the 64bit dll still crashes. At least I've got functionality though, thanks man. Also the default C# console stays open even when the terminal is open, I'm assuming that's normal.

Cfyz

  • Rogueliker
  • ***
  • Posts: 194
  • Karma: +0/-0
    • View Profile
    • Email
Re: BearLibTerminal: a pseudo-terminal window library for roguelike
« Reply #53 on: July 29, 2015, 10:16:47 AM »
Most likely 64-bit dll 'crashes' because the application is 32-bit. You cannot use 64-bit libraries from 32-bit application and vice versa. Even though your application is .NET, it all comes down to native code instructions at some point. Hence the 'Build' -> 'Platform Target' / 'Prefer 32-bit' options in project settings. I do not know of a way around this short of rewriting the whole Terminal in C#. And 32-bit works everywhere anyway.

Default console is there because of application type ('Application' -> 'Output Type' in project settings), switch it to 'Windows Application'. You could have created windows project instead but then MSVS would generate an unnecessary window form, switching one option is easier.
« Last Edit: July 29, 2015, 10:21:38 AM by Cfyz »

Untrustedlife

  • Rogueliker
  • ***
  • Posts: 162
  • Karma: +0/-0
    • View Profile
    • My Blog
    • Email
Re: BearLibTerminal: a pseudo-terminal window library for roguelike
« Reply #54 on: August 02, 2015, 03:38:50 AM »
Looks interesting, Ill check it out.

LisacPisac

  • Newcomer
  • Posts: 9
  • Karma: +0/-0
    • View Profile
    • Email
Re: BearLibTerminal: a pseudo-terminal window library for roguelike
« Reply #55 on: October 10, 2015, 07:04:07 PM »
Hey! Your library looks great, and I'm trying to make a roguelike with it. However, as usual, I get stuck at the beginning. Namely, it seems that terminal_set() does absolutely nothing in my game. It doesn't change the window size, font, or anything. I am using Windows 8.1 64-bit Pro, with MinGW 4.8.

I compile it with
g++ map.cpp -L. -lBearLibTerminal -o map.exe -static-libgcc -static-libstdc++

Could you please help me out?

Cfyz

  • Rogueliker
  • ***
  • Posts: 194
  • Karma: +0/-0
    • View Profile
    • Email
Re: BearLibTerminal: a pseudo-terminal window library for roguelike
« Reply #56 on: October 10, 2015, 07:29:24 PM »
Look if there is bearlibterminal.log being generated near your executable (or in the directory you run the program from); if there are issues with configuration string, the library will complain there. If the situation not becoming clearer, post the code sample with your terminal_set call, it will help diagnosing the problem.

LisacPisac

  • Newcomer
  • Posts: 9
  • Karma: +0/-0
    • View Profile
    • Email
Re: BearLibTerminal: a pseudo-terminal window library for roguelike
« Reply #57 on: October 11, 2015, 09:00:02 AM »
Here's a paste of my code.

http://pastebin.com/NaWYrqNk

Cfyz

  • Rogueliker
  • ***
  • Posts: 194
  • Karma: +0/-0
    • View Profile
    • Email
Re: BearLibTerminal: a pseudo-terminal window library for roguelike
« Reply #58 on: October 11, 2015, 10:48:48 AM »
Now, this one was easy. Somehow documentation was missing the fact that before terminal_open no other library call will do anything, my bad.
So just swap open and set around.

LisacPisac

  • Newcomer
  • Posts: 9
  • Karma: +0/-0
    • View Profile
    • Email
Re: BearLibTerminal: a pseudo-terminal window library for roguelike
« Reply #59 on: October 11, 2015, 11:11:15 AM »
Dead simple. Thanks! Also, on the topic of documentation, reading through the replies of this thread, I notice that certain tricks and interesting things aren't mentioned in the API reference. Things like the various tags that can be used in print functions and such. It'd be great if you could expand the documentation in that direction.