C/C++ How Does Dynamic Linking Work On Different Platforms?

后端 未结 9 1110
渐次进展
渐次进展 2020-12-24 03:20

How does dynamic linking work generally?

On Windows (LoadLibrary), you need a .dll to call at runtime, but at link time, you need to provide a corresponding .lib fi

9条回答
  •  一整个雨季
    2020-12-24 03:42

    Like others already said: what is included in a .lib file on Windows is included directly in the .so/.dynlib on Linux/OS X. But the main question is... why? Isn't *nix solution better? I think it is, but the .lib has one advantage. The developer linking to the DLL doesn't actually need to have access to the DLL file itself.

    Does a scenario like that happen often in the real world? Is it worth the effort of maintaining two files per DLL file? I don't know.

    Edit: Ok, guys let's make things even more confusing! You can link directly to a DLL on Windows, using MinGW. So the whole import library problem is not directly related to Windows itself. Taken from sampleDLL article from MinGW wiki:

    The import library created by the "--out-implib" linker option is required iff (==if and only if) the DLL shall be interfaced from some C/C++ compiler other than the MinGW toolchain. The MinGW toolchain is perfectly happy to directly link against the created DLL. More details can be found in the ld.exe info files that are part of the binutils package (which is a part of the toolchain).

提交回复
热议问题