简体   繁体   中英

How do I fix opening terminal error with c++ ncurses

I'm using CLion 2018.2.6 on MacOS. I'm trying to use ncurses but getting the error "Error opening terminal: unknown." I'm not sure how to fix this. Any help appreciated. Code below.

#include <iostream> 
#include <ncurses.h>
using namespace std;
int main(){
     initscr();
     clear();
     printw("Seems legit!");
     refresh();
     getch();
     endwin();
}

The initscr manual page mentions this:

Unset TERM Variable

If the TERM variable is missing or empty, initscr uses the value "unknown" , which normally corresponds to a terminal entry with the generic (gn) capability. Generic entries are detected by setupterm (see curs_terminfo(3x)) and cannot be used for full-screen operation. Other implementations may handle a missing/empty TERM variable differently.

Also, depending on how your system is configured, ncurses may not even find the terminal database, eg, if it is installed in a different location than the compiled-in default location. Like TERM, that can be fixed using the TERMINFO or TERMINFO_DIRS environments. As an additional complication, MacOS by default uses case-insensitive filesystems, and ncurses uses a different directory organization for that. The term(5) manual page mentions that:

A small number of terminal descriptions use uppercase characters in their names. If the underlying filesystem ignores the difference between uppercase and lowercase, ncurses represents the "first character" of the terminal name used as the intermediate level of a directory tree in (two-character) hexadecimal form.

Check the path of terminfo folder in the application running system and the same path in your application like this,

Ex:- setenv("TERMINFO","/usr/share/terminfo", 1);

It working.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM