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

后端 未结 9 1129
渐次进展
渐次进展 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:50

    You can use a DLL file in Windows in two ways: Either you link with it, and you're done, nothing more to do. Or you load it dynamically during run-time.

    If you link with it, then the DLL library file is used. The link-library contains information that the linker uses to actually know which DLL to load and where in the DLL functions are, so it can call them. When your program is loaded, the operating system also loads the DLL for you, basically what is does it call LoadLibrary for you.

    In other operating systems (like OS X and Linux) it works in a similar way. The difference is that on these systems the linker can look directly at the dynamic library (the .so/.dynlib file) and figure out what's needed without a separate static library like on Windows.

    To load a library dynamically, you don't need to link with anything related to the library you want to load.

提交回复
热议问题