Windows 上 *.a 和 *.dll 之间的区别

发布于 2024-08-19 01:09:24 字数 255 浏览 4 评论 0原文

Windows 上的 *.a*.dll 有什么区别?据我了解,可以将所有 *.o 文件打包到 *.a 中,这是 Linux 上其他应用程序可以使用的可分发文件。

但是*.a*.dll有什么区别呢?它们可以互换吗?如果我的应用程序需要链接到 *.a,我可以将其链接到 *.dll 作为替代吗?

What is the difference between *.a and *.dll on Windows? From what I understand one can package all the *.o files into a *.a, which is a distributable that other application can use, on Linux.

But what are the difference between *.a and *.dll? Are they interchangeable? If my application needs to link to *.a, can I link it to *.dll as a substitute?

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

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

发布评论

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

评论(3

人间☆小暴躁 2024-08-26 01:09:24

旁白:普通 Windows 开发工具没有定义 *.a 格式,除非您使用基于 Linux 的工具链。您可能指的是静态库,即 Windows 中的 .lib。

DLL 相当于 Unix 上的共享库 (*.so),不,如果链接器希望您链接静态库,您通常无法链接到共享库/dll。

Aside: There is no defined *.a format with plain Windows development tools, unless you use a Linux-based tool chain. You're presumably referring to a static library, aka .lib in Windows.

A DLL is the equivalent of a shared library (*.so) on Unix and no, you normally can't link to a shared library/dll if the linker expects you to link against a static library.

献世佛 2024-08-26 01:09:24

由于 *.a 是 Linux 静态库,因此它们与 Windows .dll(动态链接库)完全不能互换,因为它们具有完全不同的格式。如果您的应用程序需要链接到您创建的 .a,您将需要将生成 Linux 静态库(如果可能)的源代码重新编译为 Windows 静态库 (.lib),并针对该库编译您的代码。

Seeing that *.a are Linux static libraries, they are not at all interchangeable with windows .dll (dynamic linking libraries),as they have entirely different formats. If your application needs to link to an .a that you created, you will need to recompile the source code that generated your linux static library (if possible) into a windows static library (.lib), and compile your code against that.

终陌 2024-08-26 01:09:24

在使用 gcc 的 Linux 下,您将看到两种文件:存档 *.a(用于提供一组静态链接的函数)和 *.so,所谓共享对象库(动态链接)。对于大多数编译器来说,它们在 Windows 下的等效项是 *.lib*.dll

因此 *.a*.dll 根本不能互换。此外,在 Windows 下,您还面临一个困境,即 *.lib 既可用于静态链接,又可用于动态链接(具有固定地址)。另一种方法是使用 GetProcAddress 完全动态绑定,但这需要创建包装器的开销,如果您想让 dll 适用于不同版本,这可能正是您所需要的。

您可能会认出静态库的大小,与用于动态链接的库相比,它们是巨大的。在我的项目中,我经常使用 GetProcAddress,因为我喜欢为旧应用程序添加全新 DLL 的能力,而无需再次链接所有内容。

Under Linux with gcc you will see two kind of files the archives *.a (used to provide a set of functions to link in statically) and *.so, so called shared object library (to link dynamically). Their equivalent under windows for most compilers are *.lib and *.dll.

So *.a and *.dll are not interchangeable at all. Moreover you have under windows the dilemma that a *.lib can be used for both linking statically and dynamically (with fixed addresses). Another way is to bind fully dynamically with GetProcAddress but that has to overhead of creating a wrapper, might be what you need if you want to make the dlls work for different versions.

You may recognize the static libs at their size, they are huge in comparison to the libs used to link dynamically. In my projects I really often go the way with GetProcAddress as I like the ability to just drop in the fresh new DLLs for older applications without linking everything again.

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