I sometimes see these two terms be used interchangeably.
What is the actual difference between these two terms? How are they used differently? Are there any other alternatives to these two libraries?
Software Engineering Stack Exchange is a question and answer site for professionals, academics, and students working within the systems development life cycle. It only takes a minute to sign up.Sign up to join this community
The C standard library is part of the C programming language, so it is a specification (written in English in some technical report). For example, the n1570 document is explaining what is
malloc and how it should behave.
There is also another relevant specification, the C POSIX library (which is more or less a superset of the C standard library). For example both
fork are specified by POSIX (but ignored by the C11 standard).
The GNU glibc library is an implementation of (a superset of) the C standard library and of the C POSIX library. It is some free software (mostly written in C for the GCC dialect with a bit of assembler). It uses system calls (listed in syscalls(2)) processed by the kernel. You could use some other implementation of the C standard library, like musl-libc (or dietlibc).
You could avoid any
libc and make direct system calls to the kernel by writing assembler code. This is rarely done (an example is the Bones Scheme compiler, or BusyBox). Most programs do system calls thru the
libc and take advantage of functions provided by that
libc is a corner stone of Linux systems...
Notice that there are subtle differences between what the standard requires and what happens in practice (for example, memory overcommitment affects
malloc in a non-standard way, or Linux
dlopen has more flags than what POSIX requires).
man pages on Linux in general explain how standard conforming is a function. Look for example in dlopen(3).
Every implementation of C has to supply the standard library, but not every C compiler is written by the FSF! So the GNU C compiler will use the GNU C library, and Intel's C compiler uses a different standard library (with a less catchy name). Both will be instantiations of the standard library that the C standard requires.
If you read "UNIX" for "GNU", for a long time the terms were interchangeable because they were the same thing.
Until BSD got off the ground, AT&T's UNIX library was THE C library -- because their compiler was THE C compiler (for the most part).
After BSD, then you had System V UNIX, BSD UNIX, GNU (GNU's Not Unix), and pretty soon there were C compilers everywhere, each with their own implementation of the standard library.