ivandavidov / minimal-linux-script

One script which generates live Linux ISO image with minimal effort. Based on the first published version of Minimal Linux Live: http://github.com/ivandavidov/minimal
GNU General Public License v3.0
224 stars 70 forks source link

NCurses programs? #11

Closed jlxip closed 6 years ago

jlxip commented 6 years ago

Hi again. So this time I was coding a really simple NCurses program:

#include <ncurses.h>

int main() {
    initscr();
    printw("hit a key: ");
    getch();
    return endwin();
}

I compile this with g++ test.cpp -o test -static -lncurses -ltinfo, and gives no errors.

Then, I run it on my machine, and works like a charm.

The thing is that when I copy the binary into the filesystem of the OS, when I run it from a VM, it prints: Error opening terminal: linux. So I'm guessing there's something missing, but I haven't been able to figure out what.

Ideas?

ivandavidov commented 6 years ago

You should be aware that even though you compile statically linked binaries, there are still some external resources that your executable file may rely on. In this particular case you rely on terminal information which is not provided by MLS.

Run the program with strace in the Minimal OS environment. You can use static-get to obtain strace. You will find out the problem is that there is no information about the different supported terminals. The information for the different terminals can be taken from the terminfo package from static-get (or you can copy it from your existing machine). After that you should set the TERM environment variable to point to some known terminal information and you should be just fine.

jlxip commented 6 years ago

Thank you very much! That worked perfectly. There's only so many things to learn about GNU/Linux.