<bdo id='VPzCo'></bdo><ul id='VPzCo'></ul>

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

  1. <legend id='VPzCo'><style id='VPzCo'><dir id='VPzCo'><q id='VPzCo'></q></dir></style></legend><tfoot id='VPzCo'></tfoot>
    <i id='VPzCo'><tr id='VPzCo'><dt id='VPzCo'><q id='VPzCo'><span id='VPzCo'><b id='VPzCo'><form id='VPzCo'><ins id='VPzCo'></ins><ul id='VPzCo'></ul><sub id='VPzCo'></sub></form><legend id='VPzCo'></legend><bdo id='VPzCo'><pre id='VPzCo'><center id='VPzCo'></center></pre></bdo></b><th id='VPzCo'></th></span></q></dt></tr></i><div id='VPzCo'><tfoot id='VPzCo'></tfoot><dl id='VPzCo'><fieldset id='VPzCo'></fieldset></dl></div>
    1. C/C++ 动态链接如何在不同平台上工作?

      时间:2023-10-17

      <small id='65Gh8'></small><noframes id='65Gh8'>

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

            <tbody id='65Gh8'></tbody>

          <tfoot id='65Gh8'></tfoot>
            <legend id='65Gh8'><style id='65Gh8'><dir id='65Gh8'><q id='65Gh8'></q></dir></style></legend>
              <bdo id='65Gh8'></bdo><ul id='65Gh8'></ul>
                本文介绍了C/C++ 动态链接如何在不同平台上工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                动态链接通常如何工作?

                How does dynamic linking work generally?

                在Windows(LoadLibrary)上,运行时需要.dll来调用,但是在链接时,需要提供对应的.lib文件,否则程序不会链接....lib文件包含什么?.dll 方法的描述?这不是标题包含的内容吗?

                On Windows (LoadLibrary), you need a .dll to call at runtime, but at link time, you need to provide a corresponding .lib file or the program won't link... What does the .lib file contain? A description of the .dll methods? Isn't that what the headers contain?

                相关地,在 *nix 上,您不需要 lib 文件...编译器如何知道头文件中描述的方法将在运行时可用?

                Relatedly, on *nix, you don't need a lib file... How how does the compiler know that the methods described in the header will be available at runtime?

                作为新手,当您考虑两种方案中的任何一种时,然后考虑另一种,它们都没有意义......

                As a newbie, when you think about either one of the two schemes, then the other, neither of them make sense...

                推荐答案

                一一回答你的问题:

                • 动态链接将链接过程的一部分推迟到运行时.它可以以两种方式使用:隐式和显式.隐式地,静态链接器会将信息插入到可执行文件,这将导致库加载并解析必要的符号.明确地,您必须调用 LoadLibrarydlopen 手动,然后 GetProcAddress/dlsym 为每个您需要使用的符号.隐式加载用于事物就像系统库一样,实现将取决于系统版本,但接口有保证.显式加载用于插件之类的东西,其中要加载的库将在运行时确定.

                • Dynamic linking defers part of the linking process to runtime. It can be used in two ways: implicitly and explicitly. Implicitly, the static linker will insert information into the executable which will cause the library to load and resolve the necessary symbols. Explicitly, you must call LoadLibrary or dlopen manually, and then GetProcAddress/dlsym for each symbol you need to use. Implicit loading is used for things like the system library, where the implementation will depend on the version of the system, but the interface is guaranteed. Explicit loading is used for things like plug-ins, where the library to be loaded will be determined at runtime.

                .lib 文件仅用于隐式加载.它包含图书馆实际提供的信息符号,所以链接器不会抱怨符号是未定义,它告诉链接器符号在哪个库中被定位,所以它可以插入必要的信息来导致这个库要自动加载.所有头文件告诉编译器符号将存在于某处;这链接器需要 .lib 知道在哪里.

                The .lib file is only necessary for implicit loading. It contains the information that the library actually provides this symbol, so the linker won't complain that the symbol is undefined, and it tells the linker in what library the symbols are located, so it can insert the necessary information to cause this library to automatically be loaded. All the header files tell the compiler is that the symbols will exist, somewhere; the linker needs the .lib to know where.

                在Unix下,所有的信息都是从.so.为什么 Windows 需要两个单独的文件,而不是将所有信息放在一个文件中,我不知道;它是实际上复制了大部分信息,因为.lib 中需要的信息在 .dll 中也需要.(也许是许可问题.您可以分发您的程序.dll,但没有人可以链接到库,除非他们有一个 .lib.)

                Under Unix, all of the information is extracted from the .so. Why Windows requires two separate files, rather than putting all of the information in one file, I don't know; it's actually duplicating most of the information, since the information needed in the .lib is also needed in the .dll. (Perhaps licensing issues. You can distribute your program with the .dll, but no one can link against the libraries unless they have a .lib.)

                要保留的主要内容是,如果您想要隐式加载,您必须向链接器提供适当的信息,使用 .lib.so 文件,以便它可以插入信息进入可执行文件.如果你想明确加载,你不能引用库中的任何符号直接地;你必须调用 GetProcAddress/dlsym 来获取他们的自己称呼自己(并做一些有趣的演员来使用它们).

                The main thing to retain is that if you want implicit loading, you have to provide the linker with the appropriate information, either with a .lib or a .so file, so that it can insert that information into the executable. And that if you want explicit loading, you can't refer to any of the symbols in the library directly; you have to call GetProcAddress/dlsym to get their addresses yourself (and do some funny casting to use them).

                这篇关于C/C++ 动态链接如何在不同平台上工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:是否可以在不使用 main() 函数的情况下编写程序? 下一篇:使用类成员作为 WNDPROC/DLGPROC 有或没有全局

                相关文章

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

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

                    <legend id='W1hMF'><style id='W1hMF'><dir id='W1hMF'><q id='W1hMF'></q></dir></style></legend>
                    <tfoot id='W1hMF'></tfoot>