Search code examples
c++mingwncursesterminfo

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


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?


Solution

  • 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: