相关资料
https://en.wikipedia.org/wiki/Static_library
《深入理解计算机系统》链接
# man ar
# man ranlib
In computer science, a static library or statically-linked library is a set of routines, external functions and variables which are resolved in a caller at compile-time and copied into a target application by a compiler, linker, or binder, producing an object file and a stand-alone executable.
静态库、静态链接库
将所有相关的目标模块打包成为一个单独的文件,称为静态库,它可以用做链接器的输入。
当链接器构造一个可输出的可执行文件时,它只复制静态库里被应用程序引用的目标模块。
在 Linux 系统中,静态库以一种称为存档(archive)的特殊文件格式存放在磁盘中。存档文件是一组连接起来的可重定位目标文件的集合,有一个头部用来描述每个成员目标文件的大小和位置。
存档文件名由后缀 .a 标识。
ar
The GNU ar program creates, modifies, and extracts from archives.
An archive is a single file holding a collection of other files in a structure that makes it possible to retrieve the original individual files.
The original files' contents, mode (permissions), timestamp, owner, and group are preserved in the archive, and can be restored on extraction.
r : Insert the files member... into archive (with replacement).
c : Create the archive.
s : Add an index to the archive, or update it if it already exists.
t : Display a table listing the contents of archive, or those of the files listed in member... that are present in the archive.
v : This modifier requests the verbose version of an operation.
# ar rcs libxxx.a xxx1.o xxx2.o
创建静态库。
# ar t libxxx.a
显示文件列表。
# ar tv libxxx.a
显示文件列表详细信息。
ranlib
ranlib generates an index to the contents of an archive and stores it in the archive.
The index lists each symbol defined by a member of an archive that is a relocatable object file.
You may use nm -s to list this index.
# ranlib libxxx.a
添加索引。
nm
GNU nm lists the symbols from object files objfile....
显示符号表。
# -s
When listing symbols from archive members, include the index: a mapping of which modules contain definitions for which names.
# nm libxxx.a
显示符号表。
# nm -s libxxx.a
显示带索引的符号表。
hello.h
#ifndef HELLO_H
#define HELLO_H
void hello(const char *name);
#endif
hello.c
#include <stdio.h>
void hello(const char *name)
{
printf("hello,%s!\n",name);
}
main.c
#include "hello.h"
int main()
{
hello("world");
return 0;
}
编译运行
# gcc -c hello.c
# ar rcs libhello.a hello.o
# gcc main.c libhello.a -o hello
# ./hello
说明
静态库是由.o文件创建的。因此必须将源程序先编译成.o文件。
静态库文件名的命名规范是:以lib为前缀,紧接着是静态库名,扩展名为.a。
看的我热血沸腾啊
叼茂SEO.bfbikes.com
怎么收藏这篇文章?
不错不错,我喜欢看 https://www.ea55.com/
《妖狐苏妲己》爱情片高清在线免费观看:https://www.jgz518.com/xingkong/61980.html