0

Is library a collection of header files? Do Header files only contain function prototypes? I read that libraries are written in machine code itself, is it true? If so, why?

Everywhere it's said that library doesn't contain header files but if they have the implementation details of the functions then header files absolutely make the subset of library.

  • 1
    The header files describe the library's api. They are not the library. Most libraries are written by humans in some high level language and converted to machine code by a compiler; they are not "written in machine code itself". – William Pursell Jul 07 '23 at 13:09

1 Answers1

2

A C library is a binary file to which an executable or another library can be linked. The library itself usually is not written in machine code. Instead it is written in C or another high level language and compiled into machine code. A library comes with one or multiple header files that contain at least the declarations of the exposed library functions. So, you could say that the header file is the librarie`s API, while the binary files contain the implementation in form of machine code.

However, there are also header-only libraries, which, as the name implies, only consist of header files. Here, the *.h files contain the definition of functions, rather than only the function prototypes.

maebex
  • 21
  • 2
  • 1
    suggestion, it sometimes nice to provide a link when claiming such things as _["there are also header-only libraries..."](https://en.wikipedia.org/wiki/Header-only)_ – ryyker Jul 07 '23 at 14:12