gpt4 book ai didi

linker - 静态库和动态库: Confusion

转载 作者:行者123 更新时间:2023-12-04 13:29:47 25 4
gpt4 key购买 nike

我在这方面需要澄清。我觉得Static libraryDynamic Library这两个术语不正确。

  • lib1.o + lib2.o + lib3.o->“LinkerOutputFile”(可执行文件或库)。
  • 如果此“LinkerOutputFile”包含所有文件lib1.o,lib2.o,lib3.o的代码,则表示“LinkerOutputFile”是横向链接的“LinkerOutputFile”(可执行文件或库)。 (或)
  • 如果“LinkerOutputFile”仅包含对lib1.o,lib2.o,lib3.o的的引用和其他信息,但不包含这些lib * .o文件的代码。然后其表示“LinkerOutputFile”是动态链接的。

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

    还是“LinkerOutputFile”是一个库而不是可执行文件,取决于它的静态链接还是动态链接,称为静态库还是动态库。对或错?

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

    On most unix-style platforms the extensions are

    • .a for static libraries (archives) and
    • .so for shared libraries.

    On Windows:

    • .dll indicates a shared library
    • .lib indicates a static or import library.


    但是无法弄清楚我错了。另外,请告诉我Static libraryDynamic Library在内部有何不同。

    同样,这是来自ABI规范:

    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.

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

    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扩展名)的另一种说法。但是“静态库”呢?这甚至都没有提及。

    “可重定位”与“静态库”与“导入库”之间有什么区别吗?请用内部结构来说明我。

    最佳答案

    .o文件不是类型的库文件中的。它们是一个对象文件。
    .a/.lib文件在构建时链接。事后便无法更换它们。这使它们成为静态的。
    .so/.dll文件在运行时链接。在执行开始之前的任何时候都可以更换它们。这使它们充满活力。

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

    关于linker - 静态库和动态库: Confusion,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2246799/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com