User Tools

Site Tools


programming:ncurses

This is an old revision of the document!


ncurses

Installation

Debian package

In Debian, the easiest way to install is with:

sudo apt install libncurses6

Build from source

To build from source, get the latest version from the download page.

# Download ncurses
wget ftp://ftp.invisible-island.net/ncurses/ncurses.tar.gz
# Extract
tar xzf ncurses.tar.gz
# Enter the directory
cd ncurses-6.3
 
# Typical build steps
./configure --help | less
# Set to install in home rather than system
./configure --prefix=$HOME/.local --with-shared
make
make install

If you install to your home rather than the system, when compiling, linking, and running, you may need to specify where the header files and libraries are. With gcc, that's the -I and -L options. When running, set the environment variable LD_LIBRARY_PATH to include path to libraries.

Documentation

Man pages

There are a few man pages that are particularly helpful. The man pages with API documentation will be in ~/.local/share/man/man{1,3,5,7} if you used the home prefix.

If you aren't sure which man pages mean what, run man man which tells you which man page number corresponds to which section. (1 is executable, 3 is library calls, 5 is file formats, 7 is misc).

# Read the developer documentation (page 3)
# This page tells you the #include statement to use,
# how to link against it, and instructions on how to
# initialize and use the library itself.
# It also lists out all the man pages for each function
man 3 ncurses
 
man 3 initscr
man 3 getch
man 3 getmouse
 
man 1 ncurses6-config

Online Docs

ncurses6-config tool

Ncurses comes with a helper function useful for these tasks, ncurses6-config which will be in ~/.local/bin/ if you used the home prefix.

# For compiling and specifying include dirs
ncurses6-config --cflags
# -D_DEFAULT_SOURCE -D_XOPEN_SOURCE=600 -I/home/dano/.local/include/ncurses -I/home/dano/.local/include
 
# For linking and specifying lib dirs
ncurses6-config --libs
# -L/home/dano/.local/lib -lncurses
 
# For LD_LIBRARY_PATH when executing and linking dynamically
ncurses6-config  --libdir
#/home/dano/.local/lib

Hello world example

hello_curses.cpp
 
int main(int argc, char* argv[]) {
  return 0;
}
programming/ncurses.1647668173.txt.gz · Last modified: 2022/03/19 05:36 by nanodano