ncurses program using MinGW-w64 fails with "Error opening terminal: xterm"

845 Views Asked by At

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?

4

There are 4 best solutions below

1
Thomas Dickey On BEST ANSWER

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:

1
abdeldiaz On

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!!!

0
Laszlo On

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.

0
Zhen On
$ export TERMINFO=`ncursesw6-config --terminfo`