1

I am trying to write a very simple ncurses program, just to play around with, using mingw-w64 on Windows 10. I installed the mingw-w64-x86_64-ncurses package with pacman, and am using the MSYS2 MinGW64 environment terminal. I have no experience with any curses library and very little experience in general developing software on Windows.

I have written the following hello world program in Main.cpp:

#include <iostream>
#include <ncurses.h>
#include "Headers.hpp"

int main(int argc, char ** argv) {
    initscr();
    printw("Hello World!");
    refresh();
    getch();
    endwin();
    return 0;
}

I compile this with the following command:

g++ -I /C/msys64/mingw64/include/ncurses HelloWorld.cpp -L/C/msys64/mingw64/bin -lncursesw6 -o main

It compiles, but when I run main.exe, I get

Error opening terminal: xterm.

Why does this happen, and how can I fix it?

Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105
  • I can reproduce, but it works if I run the program in `cmd`. Probably `mintty` doesn't count as a true interactive console for this library. – HolyBlackCat Feb 05 '23 at 06:49
  • @HolyBlackCat Somehow the `TERM` env var needs to be *unset* for the mingw build to work. On the contrary, the `TERM` env var needs to be *set* for the msys build to work. Not sure what's the rationale behind. – Tom Yan Feb 05 '23 at 07:58

3 Answers3

1

I had similar problem using the ucrt64 environment on msys2. Seems the proper configuration for xterm can not be found. Try:

export TERM=xterm
export TERMINFO=<path_to_ncurse_build>/share/terminfo
./my_program.exe

It should work. Have good coding!!!

abdeldiaz
  • 11
  • 1
  • 4
0

The MInGW build works for Windows console (see README.MinGW). Other platforms use $TERM. msys2's mingw32 and mingw64 configurations are used for targeting the Windows console. Use the msys2 configuration if you want a program to work in that configuration.

The Windows Console API uses function-calls rather than writing characters (and escape sequences). This is different from mintty (used in msys2), xterm, Windows Terminal.

Further reading:

Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105
  • This is very clarifying, thank you. Like you said, it works on the Windows console. However, when I try to run the program while SSH-ing from a remote computer, also using the Windows console, I face the same issue from the original question, even when using the `ssh -t` option. Is there something different about running it like this? – Stunk x Chunk Feb 06 '23 at 22:37
0

This answer (on this page) somewhat worked for me. Here are the example commands that I have given:

export TERM=xterm

export TERMINFO=/mingw64/share/terminfo

Then executed my program with: ./hello.exe

However "MSYS2 MinGW x64" terminal did not work that well. So I tried the Windows Command Prompt (Windows 11) and that worked very well.

Laszlo
  • 302
  • 1
  • 10