简体   繁体   中英

Are library files corresponding to stdio.h dynamically linked or statically linked

I mean the math library is dynamically linked.So i was thinking that library files corresponding to stdio.h( printf and scanf codes ) are dynamically linked ? Also when we include stdio.h , then all functions declared in it are added at run time or only those functions which are used ?

On Linux and many other *nix systems, you typically link the C standard library dynamically, it's the default with gcc and clang . But you're still free to link statically if you want to. It entirely depends on your system, environment, toolchain and personal settings.

Also when we include stdio.h , then all functions declared in it are added at run time or only those functions which are used ?

Including a header doesn't link anything. The C standard library is linked automatically by C compilers, otherwise you would get undefined reference errors at the linking step if you use functions that are declared in eg stdio.h .

That said, with dynamic linking, the whole library is loaded at runtime when it is needed by the dynamic linker -- there's no way to load individual functions. The benefit with dynamic linking is that the OS only needs a single copy of this library, no matter how many processes link to it. The library can just be mapped in every processes address-space that needs it. This saves RAM at runtime.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM