Search code examples
clinuxstandard-libraryc-standard-library

In a C program, what exactly happens under the hood if I call a function from a header file from /usr/include?


The header files of C library functions can be found under /usr/include. The actual source files, however, don't seem to be simply located anywhere in the file system.

So what exactly happens under the hood if I call a function from a header file from /usr/include in my C program?


Solution

  • The implementation of the C library is typically stored on the system as a shared library which typically has a .so extension. These libraries typically live in /usr/lib, although they can reside in other locations based on the system.

    When your program is compiled and linked, it is automatically linked to the C standard library. Then when it runs, it loads the shared libraries that are linked with it.