Setting up the ncurses library on Ubuntu 12.04

14,540

Here is a totally trivial program that uses (barely) the ncurses library:

#include "ncurses.h"
int main(int argc, char** argv)
{
  /* Yes, I know, but you don't care about actually using ncurses for the moment */
  return 0;
}

Compile with:

 gcc test.c -o test -lncurses

Then run with:

  ./test

I've found this tutorial to be a good starting point and this howto to be quite a useful reference when dealing with ncurses.

Share:
14,540
asheeshr
Author by

asheeshr

New to Stack Exchange? See my short guide on the basics. If you are participating on a beta site, then The Real Essential Questions of Every Beta is an important resource to read! Some of my work can be found on Github.

Updated on June 15, 2022

Comments

  • asheeshr
    asheeshr almost 2 years

    I installed the package libncurses5-dev from the Software Center and then checked for the header file :

    asheesh@ashrj-U32U:~$ ls -l /usr/include/*curses.h
    -rw-r--r-- 1 root root 76291 Nov 18  2011 /usr/include/curses.h
    lrwxrwxrwx 1 root root     8 Nov 18  2011 /usr/include/ncurses.h -> curses.h
    -rw-r--r-- 1 root root 12180 Apr 11  2011 /usr/include/slcurses.h
    

    Then, i checked for the library files :

    asheesh@ashrj-U32U:~$ find /usr/lib/ -name "*curses*"
    ....
    /usr/lib/x86_64-linux-gnu/libcurses.a
    /usr/lib/x86_64-linux-gnu/libncurses.so
    /usr/lib/x86_64-linux-gnu/libcurses.so
    /usr/lib/x86_64-linux-gnu/libncurses.a
    ....
    

    which are not present.

    How do i install/make the library files ? Why werent they set up along with the standard package ?

    On simply compiling, i get the error :

    asheesh@ashrj-U32U:~$ gcc -o screen1 screen1.c -lcurses
    asheesh@ashrj-U32U:~$ screen1
    No command 'screen1' found, did you mean:
     Command 'screen' from package 'screen' (main)
    screen1: command not found
    

    How do i use these library files ?

  • asheeshr
    asheeshr over 11 years
    [Facepalm to self] Apparently specifying the complete directory was needed, nothing else.
  • MestreLion
    MestreLion about 9 years
    @AsheeshR: it's not needed if the executable is in your PATH. Turns out the current directory isn't, for a very good reason ;)