静态库动态库:混乱 [英] Static library & Dynamic library : Confusion

查看:93
本文介绍了静态库动态库:混乱的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这方面需要澄清.我觉得Static library& Dynamic Library不正确.

I need little clarification in this area. I feel that the terms Static library & Dynamic Library are not correct.

  • lib1.o + lib2.o + lib3.o->"LinkerOutputFile"(可执行文件或库).
  • 如果此"LinkerOutputFile"包含所有文件lib1.o,lib2.o和lib3.o的代码,则其表示"LinkerOutputFile"是横向链接的"LinkerOutputFile"(可执行文件或库). (或)

  • lib1.o + lib2.o + lib3.o --> "LinkerOutputFile"(executable or library).
  • If this "LinkerOutputFile" contains the code of all the files lib1.o , lib2.o, lib3.o then its said that "LinkerOutputFile" is satically-linked "LinkerOutputFile"(executable or library). (or)

如果"LinkerOutputFile"仅包含引用& 关于的其他有关lib1.o,lib2.o,lib3.o的信息,但不包含这些lib * .o文件的代码.然后它说"LinkerOutputFile"是动态链接的.

If "LinkerOutputFile" just contains references & other information about to lib1.o, lib2.o, lib3.o without containing the code of these lib*.o files. Then its said that "LinkerOutputFile" Dynamically linked.

这如何使lib * .o文件成为静态库还是动态库?它们只是库文件.

How does this make lib*.o files either a static library or dynamic library? They are just library files.

或者,"LinkerOutputFile"是一个库而不是可执行文件,则取决于它的静态链接库还是动态链接库(称为静态库或动态库).对还是错?

Or is it that, "LinkerOutputFile" is a library instead of executable then depending on whether its statically-linked or dynamically-linked its called static-library or dynamic-library. True or False?

我知道我错了,因为,我知道

I know I'm wrong, because, I know that

在大多数Unix风格的平台上, 扩展名是

On most unix-style platforms the extensions are

  • .a 用于静态库(档案)和
  • .so 用于共享库.
  • .a for static libraries (archives) and
  • .so for shared libraries.

在Windows上:

  • .dll 表示共享库
  • .lib 表示静态或导入库.
  • .dll indicates a shared library
  • .lib indicates a static or import library.

但是无法弄清楚我错了.另外,请告诉我Static library& Dynamic Library内部不同.

But can't figure out where I'm wrong. Also please tell me how are Static library & Dynamic Library internally different.

这也是来自ABI规范:

Also, this is from ABI specification:

本章介绍目标文件 格式,称为ELF(可执行文件和 链接格式).主要有三个 对象文件的类型.

This chapter describes the object file format, called ELF (Executable and Linking Format). There are three main types of object files.

一个可重定位文件保存代码和数据 适合与其他对象链接 文件来创建可执行文件或 共享对象文件.

A relocatable file holds code and data suitable for linking with other object files to create an executable or a shared object file.

一个可执行文件包含一个程序 适合执行;文件 指定exec(BA_OS)如何创建一个 程序的过程映像.

An executable file holds a program suitable for execution; the file specifies how exec(BA_OS) creates a program's process image.

一个共享对象文件包含代码, 适用于两个链接的数据 上下文.首先,链接编辑器[请参见 ld(BA_OS)]处理共享库 与其他可重定位和共享的文件 对象文件来创建另一个对象 文件.二,动态链接器 将其与可执行文件结合 和其他共享对象创建一个 过程映像.

A shared object file holds code and data suitable for linking in two contexts. First, the link editor [see ld(BA_OS)] processes the shared object file with other relocatable and shared object files to create another object file. Second, the dynamic linker combines it with an executable file and other shared objects to create a process image.

共享目标文件"是动态库(具有* .so扩展名)的另一种说法.但是静态库"呢?这甚至都没有提及.

"shared object file" are other words for saying Dynamic Library(has *.so extension). But what about "Static library"? This doesn't even mention it.

可重定位"与"静态图书馆"和导入图书馆"?请通过内部结构来说明我.

Is there any difference between, "Relocatable" & "Static Library" & "Import Library"? Please clarify me with internal structure.

推荐答案

.o文件不是任何种库文件.它们是对象文件.

.o files are not any kind of library file. They are an object file.

.a/.lib文件在构建时链接.事后便无法更换它们.这使它们成为静态的.

.a/.lib files are linked at build time. They cannot be replaced after the fact. This makes them static.

.so/.dll文件在运行时链接.在执行开始之前的任何时候都可以更换它们.这使它们充满活力.

.so/.dll files are linked at runtime. They can be replaced any time before execution starts. This makes them dynamic.

重定位是指二进制文件在内存中的放置;静态库中的代码已与二进制文件集成在一起,因此不能独立地重定位.

Relocation refers to placement of a binary in memory; code from static libraries is integrated with the binary and so can't be relocated independently.

这篇关于静态库动态库:混乱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆