• <legend id='aavT0'><style id='aavT0'><dir id='aavT0'><q id='aavT0'></q></dir></style></legend>

    <i id='aavT0'><tr id='aavT0'><dt id='aavT0'><q id='aavT0'><span id='aavT0'><b id='aavT0'><form id='aavT0'><ins id='aavT0'></ins><ul id='aavT0'></ul><sub id='aavT0'></sub></form><legend id='aavT0'></legend><bdo id='aavT0'><pre id='aavT0'><center id='aavT0'></center></pre></bdo></b><th id='aavT0'></th></span></q></dt></tr></i><div id='aavT0'><tfoot id='aavT0'></tfoot><dl id='aavT0'><fieldset id='aavT0'></fieldset></dl></div>
    • <bdo id='aavT0'></bdo><ul id='aavT0'></ul>

        <small id='aavT0'></small><noframes id='aavT0'>

        <tfoot id='aavT0'></tfoot>

        “静态链接"和“动态链接"是什么意思?

        时间:2023-08-26

      1. <tfoot id='IE1JI'></tfoot>
      2. <i id='IE1JI'><tr id='IE1JI'><dt id='IE1JI'><q id='IE1JI'><span id='IE1JI'><b id='IE1JI'><form id='IE1JI'><ins id='IE1JI'></ins><ul id='IE1JI'></ul><sub id='IE1JI'></sub></form><legend id='IE1JI'></legend><bdo id='IE1JI'><pre id='IE1JI'><center id='IE1JI'></center></pre></bdo></b><th id='IE1JI'></th></span></q></dt></tr></i><div id='IE1JI'><tfoot id='IE1JI'></tfoot><dl id='IE1JI'><fieldset id='IE1JI'></fieldset></dl></div>
          <legend id='IE1JI'><style id='IE1JI'><dir id='IE1JI'><q id='IE1JI'></q></dir></style></legend>

          <small id='IE1JI'></small><noframes id='IE1JI'>

                  <tbody id='IE1JI'></tbody>
                  <bdo id='IE1JI'></bdo><ul id='IE1JI'></ul>
                  本文介绍了“静态链接"和“动态链接"是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我经常听到静态链接"和动态链接"这两个术语,通常指的是用 C、C++ 或 C#.它们是什么,它们到底在说什么,它们在链接什么?

                  I often hear the terms 'statically linked' and 'dynamically linked', often in reference to code written in C, C++ or C#. What are they, what exactly are they talking about, and what are they linking?

                  推荐答案

                  从源代码(你写的)到可执行代码(你运行的)有两个阶段(在大多数情况下,不考虑解释代码).

                  There are (in most cases, discounting interpreted code) two stages in getting from source code (what you write) to executable code (what you run).

                  首先是将源代码转换为目标模块的编译.

                  The first is compilation which turns source code into object modules.

                  第二个,链接,是将对象模块组合在一起形成可执行文件.

                  The second, linking, is what combines object modules together to form an executable.

                  区别在于,除其他外,允许第​​三方库包含在您的可执行文件中,而您不会看到它们的源代码(例如用于数据库访问、网络通信和图形用户界面的库),或者用于在不同的语言(例如 C 和汇编代码),然后将它们链接在一起.

                  The distinction is made for, among other things, allowing third party libraries to be included in your executable without you seeing their source code (such as libraries for database access, network communications and graphical user interfaces), or for compiling code in different languages (C and assembly code for example) and then linking them all together.

                  当您静态将文件链接到可执行文件时,该文件的内容会在链接时包含.换句话说,文件的内容被物理插入到您将要运行的可执行文件中.

                  When you statically link a file into an executable, the contents of that file are included at link time. In other words, the contents of the file are physically inserted into the executable that you will run.

                  当您动态链接时,指向被链接文件的指针(例如文件的文件名)包含在可执行文件中,并且该文件的内容不包含在链接中时间.只有当您稍后运行可执行文件时,这些动态链接的文件才会被购买,并且它们只会被购买到可执行文件的内存副本中,而不是磁盘上的那个.

                  When you link dynamically, a pointer to the file being linked in (the file name of the file, for example) is included in the executable and the contents of said file are not included at link time. It's only when you later run the executable that these dynamically linked files are bought in and they're only bought into the in-memory copy of the executable, not the one on disk.

                  它基本上是一种延迟链接的方法.还有一个更多延迟方法(在某些系统上称为后期绑定),它不会引入动态链接文件,直到您实际尝试调用其中的函数.

                  It's basically a method of deferred linking. There's an even more deferred method (called late binding on some systems) that won't bring in the dynamically linked file until you actually try to call a function within it.

                  静态链接文件在链接时被锁定"到可执行文件,因此它们永远不会改变.可执行文件引用的动态链接文件只需替换磁盘上的文件即可更改.

                  Statically-linked files are 'locked' to the executable at link time so they never change. A dynamically linked file referenced by an executable can change just by replacing the file on the disk.

                  这允许更新功能而无需重新链接代码;每次运行时加载器都会重新链接.

                  This allows updates to functionality without having to re-link the code; the loader re-links every time you run it.

                  这有好有坏 - 一方面,它允许更轻松的更新和错误修复,另一方面,如果更新不兼容,它可能导致程序停止工作 - 这有时是可怕的DLL地狱"的原因有人提到,如果将动态链接库替换为不兼容的库,应用程序可能会被破坏(顺便说一下,这样做的开发人员应该会受到追捕和严厉惩罚).

                  This is both good and bad - on one hand, it allows easier updates and bug fixes, on the other it can lead to programs ceasing to work if the updates are incompatible - this is sometimes responsible for the dreaded "DLL hell" that some people mention in that applications can be broken if you replace a dynamically linked library with one that's not compatible (developers who do this should expect to be hunted down and punished severely, by the way).

                  作为一个示例,让我们看看用户编译他们的 main.c 文件以进行静态和动态链接的情况.

                  As an example, let's look at the case of a user compiling their main.c file for static and dynamic linking.

                  Phase     Static                    Dynamic
                  --------  ----------------------    ------------------------
                            +---------+               +---------+
                            | main.c  |               | main.c  |
                            +---------+               +---------+
                  Compile........|.........................|...................
                            +---------+ +---------+   +---------+ +--------+
                            | main.o  | | crtlib  |   | main.o  | | crtimp |
                            +---------+ +---------+   +---------+ +--------+
                  Link...........|..........|..............|...........|.......
                                 |          |              +-----------+
                                 |          |              |
                            +---------+     |         +---------+ +--------+
                            |  main   |-----+         |  main   | | crtdll |
                            +---------+               +---------+ +--------+
                  Load/Run.......|.........................|..........|........
                            +---------+               +---------+     |
                            | main in |               | main in |-----+
                            | memory  |               | memory  |
                            +---------+               +---------+
                  

                  您可以在静态情况下看到主程序和 C 运行时库在链接时链接在一起(由开发人员).由于用户通常无法重新链接可执行文件,因此他们被库的行为所困扰.

                  You can see in the static case that the main program and C runtime library are linked together at link time (by the developers). Since the user typically cannot re-link the executable, they're stuck with the behaviour of the library.

                  在动态情况下,主程序与 C 运行时导入库链接(它声明了动态库中的内容,但实际上并没有定义它).即使缺少实际代码,这也允许链接器进行链接.

                  In the dynamic case, the main program is linked with the C runtime import library (something which declares what's in the dynamic library but doesn't actually define it). This allows the linker to link even though the actual code is missing.

                  然后,在运行时,操作系统加载程序将主程序与 C 运行时 DLL(动态链接库或共享库或其他命名法)进行后期链接.

                  Then, at runtime, the operating system loader does a late linking of the main program with the C runtime DLL (dynamic link library or shared library or other nomenclature).

                  C 运行时的所有者可以随时插入新的 DLL 以提供更新或错误修复.如前所述,这既有优点也有缺点.

                  The owner of the C runtime can drop in a new DLL at any time to provide updates or bug fixes. As stated earlier, this has both advantages and disadvantages.

                  这篇关于“静态链接"和“动态链接"是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:Ajax 日历扩展器结束日期 下一篇:.NET 应用程序的链接器状态(又名“请先生,我可

                  相关文章

                  最新文章

                  <legend id='SQ19c'><style id='SQ19c'><dir id='SQ19c'><q id='SQ19c'></q></dir></style></legend>
                  • <bdo id='SQ19c'></bdo><ul id='SQ19c'></ul>

                    1. <small id='SQ19c'></small><noframes id='SQ19c'>

                      <tfoot id='SQ19c'></tfoot>

                      <i id='SQ19c'><tr id='SQ19c'><dt id='SQ19c'><q id='SQ19c'><span id='SQ19c'><b id='SQ19c'><form id='SQ19c'><ins id='SQ19c'></ins><ul id='SQ19c'></ul><sub id='SQ19c'></sub></form><legend id='SQ19c'></legend><bdo id='SQ19c'><pre id='SQ19c'><center id='SQ19c'></center></pre></bdo></b><th id='SQ19c'></th></span></q></dt></tr></i><div id='SQ19c'><tfoot id='SQ19c'></tfoot><dl id='SQ19c'><fieldset id='SQ19c'></fieldset></dl></div>