It is a linker error (see this, nearly a duplicate). ncurses
is generally known to pkg-config (which gives more dependencies, when required), so try to compile with:
gcc -Wall -Wextra -g \
$(pkg-config --cflags ncurses) \
get_char_example.c \
$(pkg-config --libs ncurses)
You want to Invoke GCC with all warnings and debug info; you would use GDB, perhaps under emacs
or with ddd
, for debugging.
Even better, use some build automation tool (like make
or ninja
). With GNU make
take inspiration from this to write your Makefile
(where tab-s are significant).
On my Debian Sid, pkg-config --cflags ncurses
gives -D_GNU_SOURCE -D_DEFAULT_SOURCE
and pkg-config --libs ncurses
gives -lncurses -ltinfo
, so simply linking with -lncurses
is not enough (and that is why this is not exactly a duplicate today in November 2017; a few years ago linking with simply -lncurses
was enough, today it is not).
Use pkg-config --list-all
to find all the packages and libraries known to pkg-config; when developing your libraries consider also providing some .pc
file for it.
BTW, your program should start by initializing with initscr
and use printw
; Read Ncurses-programming-HowTo even if it is a bit old.
Notice also that using ASCII in the 21st century is obsolete. Programs and computers use UTF-8 everywhere, and this has profound consequences you should be aware of (since an UTF-8 character can span several bytes). My French keyboard has keys for ²
, §
, €
and é
(even with American keyboards your could paste them) and none of these are in ASCII. Consider also using some UTF-8 library like libunistring.