What's the difference between -lcurses and -lncurses when compiling C using ncurses lib?

12,791

Solution 1

ncurses is an open-source clone of the original Unix curses library. libcurses.* usually points to libncurses.* to provide compatibility with the original library, so there would be no practical difference between using one over the other.

If you do in fact have more than one 'curses-type' library installed, -lcurses would essentially link your program to the default one, whereas -lncurses would explicitly choose the ncurses implementation.

Solution 2

On my OpenSUSE 12.3 box there are no links to libcurses with ncurses installed. Any C programs that attempt to use the -lcurses flag will fail until you change the flag to -lncurses.

OpenSUSE 12.3 > ls -al /usr/lib64/*curses*
-rw-r--r-- 1 root root 2225910 Jan 25  2013 /usr/lib64/libncurses.a
-rw-r--r-- 1 root root  780540 Jan 25  2013 /usr/lib64/libncurses++.a
-rw-r--r-- 1 root root      69 Jan 25  2013 /usr/lib64/libncurses.so
-rw-r--r-- 1 root root  782884 Jan 25  2013 /usr/lib64/libncurses++w.a
-rw-r--r-- 1 root root 2768222 Jan 25  2013 /usr/lib64/libncursesw.a
-rw-r--r-- 1 root root      70 Jan 25  2013 /usr/lib64/libncursesw.so

The links are also missing on Fedora 17. However, on Ubuntu 13.04 the links are present:

Ubuntu 13.04 > ls -al /usr/lib/x86_64-linux-gnu/*curses*
lrwxrwxrwx 1 root root     12 Feb  8  2013 /usr/lib/x86_64-linux-gnu/libcurses.a -> libncurses.a
lrwxrwxrwx 1 root root     13 Feb  8  2013 /usr/lib/x86_64-linux-gnu/libcurses.so -> libncurses.so
-rw-r--r-- 1 root root 294180 Feb  8  2013 /usr/lib/x86_64-linux-gnu/libncurses.a
-rw-r--r-- 1 root root 158798 Feb  8  2013 /usr/lib/x86_64-linux-gnu/libncurses++.a
-rw-r--r-- 1 root root     31 Feb  8  2013 /usr/lib/x86_64-linux-gnu/libncurses.so

So compiling with -lcurses will fail on OpenSUSE and Fedora but work on Ubuntu. Compiling with -lncurses will work for all three distros.

The takeaway: If you want your code to compile on different Linux distros, you should use -lncurses.

Share:
12,791
Admin
Author by

Admin

Updated on August 05, 2022

Comments

  • Admin
    Admin almost 2 years

    I'm learning C and playing with the ncurses lib. I have seen references to both -lcurses and -lncurses but I have yet to find any differences (both work when compiling).

    Appreciate the help!

  • Jonathan Leffler
    Jonathan Leffler over 14 years
    On systems such as Solaris, the libcurses.so is the original (Unix) curses library (or an enhanced curses library, but not the GNU libncurses library). On Linux systems, there is no difference.
  • Luciano
    Luciano over 7 years
    @JonathanLeffler: The same for others platforms like IBM AIX, there aren't ncurses but the original or enhanced curses.