C|应用程序编程接口(API)及其实现(Implementation)

A library implements a collection of functions and definitions that can be used by other programs. A C library consists of two parts:

库实现了可由其他程序使用的函数和定义的集合。C库由两部分组成:

The application programming interface (API) to the library, which gets defined in one or more header files (.h files) that must be included in C source code files that plan to use the library. The headers define what the library exports to its users. These definitions usually include library function prototypes, and they may also include type, constant, or global variable declarations.

库的应用程序编程接口(API),它在一个或多个头文件(.h文件)中定义,这些头文件必须包含在计划使用库的C源代码文件中。头文件定义了库导出给用户的内容。这些定义通常包括库函数原型,也可能包括类型、常量或全局变量声明。

The implementation of the library’s functionality, often made available to programs in a precompiled binary format that gets linked (added) into the binary executable created by gcc. Precompiled library code might be in an archive file (libsomelib.a, archive) containing several .o files that can be statically linked into the executable file at compile time. Alternatively, it may consist of a shared object file (libsomelib.so, shared object) that can be dynamically linked at runtime into a running program.

库功能的实现,通常以预编译的二进制格式提供给程序,该格式链接(添加)到gcc创建的二进制可执行文件中。预编译的库代码可能位于包含多个.o文件的存档文件(libsomelib.a, archive)中,这些文件可以在编译时静态链接到可执行文件。或者,它可以由一个共享对象文件(libsomelib.so, shared object)组成,该文件可以在运行时动态链接到正在运行的程序中。

For example, the C string library implements a set of functions to manipulate C strings. The string.h header file defines its interface, so any program that wants to use string library functions must #include <string.h>. The implementation of the C string library is part of the larger standard C library (libc) that the gcc compiler automatically links into every executable file it creates.

例如,C字符串库实现了一组操作C字符串的函数。字符串.h头文件定义了它的接口,因此任何想要使用字符串库函数的程序都必须包含<string.h>。C字符串库的实现是更大的标准C库(libc)的一部分,gcc编译器会自动链接到它创建的每个可执行文件中。

A library’s implementation consists of one or more modules (.c files), and may additionally include header files that are internal to the library implementation; internal header files are not part of the library’s API but are part of well-designed, modular library code. Often the C source code implementation of a library is not exported to the user of the library. Instead, the library is made available in a precompiled binary form. These binary formats are not executable programs (they cannot be run on their own), but they provide executable code that can be linked into (added into) an executable file by gcc at compilation time.

库的实现由一个或多个模块(.c文件)组成,还可以包括库实现内部的头文件;内部头文件不是库API的一部分,而是精心设计的模块化库代码的一部分。库的C源代码实现通常不会导出到库的用户。相反,该库是以预编译的二进制形式提供的。这些二进制格式不是可执行程序(它们不能自己运行),但它们提供了可执行代码,可由gcc在编译时链接到(添加到)可执行文件中。

ref

https://diveintosystems.org/

-End-

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

(0)
上一篇 2023年3月20日 上午8:53
下一篇 2023年3月20日 上午9:03

相关推荐