Visual C++:什么是动态链接的 .lib 文件?

发布于 2024-08-21 11:18:12 字数 560 浏览 4 评论 0原文

我注意到有关我使用的库的以下信息:

  • 库被编译为 .lib 文件。
  • 我的代码需要编译为多线程(调试)DLL 才能链接到该库。

我打开库的 .sln(解决方案)文件(它是开源的),并在其项目属性中看到以下内容:

  1. 运行时库选项设置为多线程(调试)DLL
  2. 配置类型设置为静态库(.lib)

我的困惑是:

  1. 上面的库选项是否有冲突? (静态库表示一个选项,DLL 表示另一个选项)
  2. 动态链接.lib是一种什么样的动物?它与 DLL 有什么不同?

请注意,我知道 Linux 世界中静态库和动态库之间的区别。

I noticed the following about a library I use:

  • Library is compiled to .lib file.
  • My code needs to be compiled as Multi-threaded (Debug) DLL to link to this library.

I open the .sln (solution) file of the library (it is open source) and see the following in its Project properties:

  1. Runtime Library option is set to Multi-threaded (Debug) DLL.
  2. Configuration Type is set to Static Library (.lib)

My confusion is:

  1. Isn't there a conflict in the library options above? (Static Library says one option, DLL says another)
  2. What kind of an animal is a .lib that is dynamically linked? How is it different from a DLL?

Note that I am aware of the difference between static libraries and dynamic libraries in the Linux world.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

面如桃花 2024-08-28 11:18:12

“运行时库”选项与您的库无关。它告诉编译器您将在运行时从 MSVCRTxx.DLL 导入函数。

“配置类型”选项确实引用了您的库,因此独立于“运行时库”选项。

The "RunTime Library" option isn't about YOUR library. It tells the compiler that you'll import your functions from MSVCRTxx.DLL at runtime.

The "configuration Type" option does refer to your library, and therefore is independent of the "RunTime Library" option.

笑红尘 2024-08-28 11:18:12

Windows DLL 可以使用 LoadLibrary (或 LoadLibraryEx)API,但是您必须使用 GetProcAddress 或 GetProcAddressEx。您最好确保函数签名正确,否则就会像往常一样发生不好的事情。

LIB 文件允许 Windows 在 EXE 启动时为您执行所有操作(包括查找要使用的 DLL,以及递归加载依赖的 DLL),在运行时静态链接动态库,同时避免可执行代码使 EXE 文件膨胀。 ,并允许多个进程共享内存中的同一个 DLL 映像。

A Windows DLL can be dynamically loaded with the LoadLibrary (or LoadLibraryEx) API, but then you have to find and bind each exported function to a function pointer using GetProcAddress or GetProcAddressEx. You'd better get the function signatures right, or Bad Things Will Happen, as usual.

A LIB file allows Windows to do all that for you when your EXE is started (including finding which DLL to use, and recursively loading dependent DLL's), linking the dynamic library statically at run time, while avoiding bloating your EXE file with the executable code, and allowing several processes to share the same DLL image in memory.

笑看君怀她人 2024-08-28 11:18:12

我不知道配置不匹配,但是使用 .DLL 库创建的 .LIB 文件是一个“导出库” - 它不包含任何代码,而只包含 DLL 中可调用函数和对象的名称。链接器使用它来满足链接时的引用,这些引用最终通过运行时的动态加载来解析。

I don't know about the config mismatch, but a .LIB file when created with a .DLL library is an "export library" - it doesn't contain any code, but just the names of the callable functions and objects in the DLL. The linker uses this to satisfy references at link time which are finally resolved by dynamic loading at run-time.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文