I've just discovered ncurses and have just started learning it, however the examples in my tutorial don't compile on my computer.
I had to install ncurses manually and did so by entering "apt-get install libncurses5-dev libncursesw5-dev". I had to do this because before having done so I got an error saying that I could not "#include ".
Installing it worked, but now I get this error instead:
touzen@comp:~/learning_ncurses$ g++ -o hello_world hello_world.cpp
/tmp/ccubZbvK.o: In function `main':
hello_world.cpp:(.text+0xa): undefined reference to `initscr'
hello_world.cpp:(.text+0x16): undefined reference to `printw'
hello_world.cpp:(.text+0x1b): undefined reference to `refresh'
hello_world.cpp:(.text+0x20): undefined reference to `stdscr'
hello_world.cpp:(.text+0x28): undefined reference to `wgetch'
hello_world.cpp:(.text+0x2d): undefined reference to `endwin'
collect2: ld returned 1 exit status
The code I compiled looks like this:
#include <ncurses.h>
int main(){
initscr();
printw("Hai thar world...");
refresh();
getch();
endwin();
return 0;
}
Why do I get this error. And even more importantly, how do I fix this?
ncurses (new curses) is a programming library providing an application programming interface (API) that allows the programmer to write text-based user interfaces (TUI) in a terminal-independent manner. It is a toolkit for developing "GUI-like" application software that runs under a terminal emulator.
In ncurses, "windows" are a means to divide the screen into logical areas. Once you define a window, you don't need to track its location on the screen; you just draw to your window using a set of ncurses functions.
The ncurses library is available for MinGW. Simply open CMD, or run PowerShell and run mingw-get install ncurses , mingw-get will both download and install the package. Just make sure the path to your MinGW bin folder is linked to your system path, and you should be able to use ncurses without trouble.
you have to link the ncurses library
g++ -o hello_world hello_world.cpp -lncurses
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With