简体   繁体   English

与stdio.h对应的库文件是动态链接还是静态链接

[英]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 ? 我的意思是数学库是动态链接的。所以我想与stdio.h(printf和scanf代码)相对应的库文件是动态链接的吗? Also when we include stdio.h , then all functions declared in it are added at run time or only those functions which are used ? 同样,当我们包含stdio.h时,在运行时添加其中声明的所有函数,或者仅添加使用的那些函数?

On Linux and many other *nix systems, you typically link the C standard library dynamically, it's the default with gcc and clang . 在Linux和许多其他* nix系统上, 通常会动态链接C标准库,这是gccclang的默认库。 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 ? 同样,当我们包含stdio.h时,在运行时添加其中声明的所有函数,或者仅添加使用的那些函数?

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 . C标准库由C编译器自动链接,否则,如果使用在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. 动态链接的好处是,无论有多少个进程链接到OS,OS都只需要该库的一个副本。 The library can just be mapped in every processes address-space that needs it. 该库可以仅映射到需要它的每个进程的地址空间中。 This saves RAM at runtime. 这样可以在运行时节省RAM。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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