I want to implement a loop in C which stops when a particular key is pressed. For this I've been trying to use the ncurses library. I have a Redhat system which is offline and cannot be connected to the internet. Upon running the command locate libncurses
I get a number of lines such as /usr/lib64/libncurses++.so.5
. I assume this means that the ncurses library is present on my system. Next I try to run the following code to test ncurses
#include <ncurses.h>
int
main()
{
initscr();
cbreak();
noecho();
scrollok(stdscr, TRUE);
nodelay(stdscr, TRUE);
while (true) {
if (getch() == 'g') {
printw("You pressed G\n");
}
napms(500);
printw("Running\n");
}
}
This has been taken from the question Using kbhit() and getch() on Linux
When I try to run this in the following manner gcc -o testncurses testncurse.c
I get the error undefined reference to 'initscr'
. Then I proceed to run it as gcc -o testncurses testncurse.c -lncurses
. But I get the error
/usr/bin/ld: cannot find -lncurses
collect2:error: ld returned 1 exit status
What should I do so that the above code runs?
I have also tried installing a newer ncurses library package but that gives me an error saying that files in the package being installed conflicts with the already installed package.