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

I am learning C and playing with ncurses lib. I have seen references to both -lcurses and -lncurses, but I have not yet found the differences (both work on compilation).

Appreciate the help!

+6
c ncurses
source share
4 answers

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

If you actually have more than one curses-type library installed, -lcurses essentially associates your program with the default, while -lncurses explicitly chooses the ncurses implementation.

+12
source share

My OpenSUSE 12.3 block has no links to libcurses with ncurses installed. Any C program that tries to use the -lcurses flag will work until you replace the flag with -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++wa -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 

Links are also missing on Fedora 17. However, there are links on Ubuntu 13.04:

 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 

Thus, compilation with -lcurses will fail on OpenSUSE and Fedora, but will work with Ubuntu. Compiling with -lncurses will work for all three distributions.

Bottom line: if you want your code to compile on different Linux distributions, you should use -lncurses.

+2
source share

On my system (Slackware64 13.0), libcurses.so and friends are just symbolic links to the ncurses equivalent, so there is no difference. The name libcurses.so ( -lcurses ) probably just provides backward compatibility with code developed for other systems that have a curse implementation other than ncurses.

0
source share

On my (fedora 11) PC, /usr/lib/libcurses.so contains: "INPUT (-lncurses)." I think this means that the two forms (-lcurses, -lncurses) are equivalent.

0
source share

All Articles