Compiling ncurses library
What is ncurses?
ncurses is a library written in C that provides API for running applications in a terminal.
See https://www.gnu.org/software/ncurses/
Why should I use it?
If you want to write an application that uses the terminal as its output, you should use it instead of trying to manipulate text in terminal by yourself. e.g Vim uses it to allow you to edit and view your files.
Step 1: Download ncurses
Go to the ncurses page and download the library.
For this tutorial I'll use ncurses 6.0
I usually put all source code in $HOME/src directory
Make ncurses directory under src
carmel@carmel:~$ cd src/ carmel@carmel:~/src$ mkdir ncurses carmel@carmel:~/src$ cd ncurses/ carmel@carmel:~/src/ncurses$ NDIR=`pwd`From now on $NDIR will be the ncurses source code directory.
Download ncurses
carmel@carmel:~/src/ncurses$ wget http://ftp.gnu.org/gnu/ncurses/ncurses-6.0.tar.gz
Extract the files:
carmel@carmel:~/src/ncurses$ tar -xvzf ncurses-6.0.tar.gz carmel@carmel:~/src/ncurses$ cd ncurses-6.0/ carmel@carmel:~/src/ncurses/ncurses-6.0$ ll
Take a look around.. If you want to learn more about the installation process, you should read the INSTALL file, its very interesting.
You should also run
./configure --help
Take a look in the configuration options and see if you need something that is not covered here.
Step 2: Configure
CPPFLAGS
Due to this issue we need to export a cpp flag
carmel@carmel:~/src/ncurses/ncurses-6.0$ export CPPFLAGS="-P"
--prefix
Use prefix option to configure changes the root directory for installing ncurses. The default is normally in subdirectories of /usr/local.
The package gets installed beneath the --prefix directory as follows:
In $(prefix)/bin: tic, infocmp, captoinfo, tset,
reset, clear, tput, toe, tabs
In $(prefix)/lib: libncurses*.* libcurses.a
In $(prefix)/share/terminfo: compiled terminal descriptions
In $(prefix)/include: C header files
Under $(prefix)/man: the manual pages
I'll install ncurses under the prefix $HOME.
With the --prefix option, the ./configure command should look like this now:
./configure --prefix=$HOME
--with-shared
Use the --with-shared option to generate shared-libraries. This is useful if you want to compile other programs with the ncurses library.
Now, with the --with-shared option the ./configure command should look like this:
Now, with the --with-shared option the ./configure command should look like this:
./configure --prefix=$HOME --with-shared
Run the configuration..
carmel@carmel:~/src/ncurses/ncurses-6.0$ ./configure --prefix=$HOME --with-shared
The last lines of the output should look like:
carmel@carmel:~/src/ncurses/ncurses-6.0$ ./configure --prefix=$HOME --with-shared ... ** Configuration summary for NCURSES 6.0 20150808: extended funcs: yes xterm terminfo: xterm-new bin directory: /home/carmel/bin lib directory: /home/carmel/lib include directory: /home/carmel/include/ncurses man directory: /home/carmel/share/man terminfo directory: /home/carmel/share/terminfo ** Include-directory is not in a standard location
If you got an error then post a comment here describing the error and I'll add it into a 'Troubleshooting' section.
Step 3: make
run:
carmel@carmel:~/src/ncurses/ncurses-6.0$ make
Step 4: make install
run:
carmel@carmel:~/src/ncurses/ncurses-6.0$ make install
Troubleshooting
Error in make
After runningmake
you get the following error:
In file included from ./curses.priv.h:325:0, from ../ncurses/lib_gen.c:19: _10346.c:843:15: error: expected ‘)’ before ‘int’ ../include/curses.h:1631:56: note: in definition of macro ‘mouse_trafo’ #define mouse_trafo(y,x,to_screen) wmouse_trafo(stdscr,y,x,to_screen) ^
this is a known issue with mawk program. see this for more details
Go through step 2 again. make sure you run
carmel@carmel:~/src/ncurses/ncurses-6.0$ export CPPFLAGS="-P"
BEFORE you configure