I'm trying to understand the Filesystem Hierarchy Standard. I have looked up both binaries and libraries, and as I currently understand it:
binaries are files of computer-readable code in binary format, that control the CPU and processor directly with bits.
libraries are functions usable by various programs, for convenience sake – like when you require a module in Javascript of PHP.
Is this understanding correct? If it is, why do we still separate libraries and binaries? Some libraries are binaries, right? And some binaries (cat, less, date, rm, cp, etc) are used and reused as though they were libraries… Can someone help explain the difference and help me find better definitions for these two words? Thank you.
Best Answer
Your understanding is mostly correct, but there are a couple of extra things to consider:
/lib
is going to be libraries compiled to machine code.cat
are used in shell script like calls to code in libraries, they are not libraries in the FHS sense because they can be run by themselves.As a result of these points, the more common terminology among people who aren't writing standards documents is:
Object files: These are natively compiled machine code, but may not even run or be callable. They typically have a
.o
extension unless they fall into one of the other categories, and are almost never seen on most systems except when building software. I've listed them here because they're important to understanding a few things below.Executable files: These are files consisting of mostly self contained code that can be run directly. They may be either specially formatted object files which can be loaded directly by the kernel (things like
cat
,bash
, andpython
are all this type of executable), or are interpreted by some intermediary program that is itself an executable (Minecraft,pydoc
, andcowsay
are all examples of this type of executable). Executables of the first type almost never have a file extension on UNIX systems, while executables of the second type may or may not. This is what the FHS refers to as 'binaries'. They can be run from other executables, but require calling special functions to invoke them (fork()
andexec()
in C and C++, things out of thesubprocess
module in Python, etc) and run as a separate process.Libraries: These are files that contain reusable code that can be invoked by another library or an executable. Code in libraries is invoked (mostly) directly by other code once the library is loaded (referred to as 'linking' when talking about compiled code), and runs in the same process as the code calling it. There are three generic types of libraries:
.a
extension. The concept of static libraries doesn't really exist outside of compiled programming languages..so
extension on UNIX (.dll
is the standard on Windows), that gets loaded at run time by executables that use it. Most of what you'll find in/lib
on production systems is dynamic libraries.http.server
in the Python standard library for an example).