在Windows中静态链接DLL [英] Statically linking a DLL in Windows

查看:48
本文介绍了在Windows中静态链接DLL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑这种情况:

我正在创建一个DLL(我们称为dllA),该DLL依次调用其他DLL中的函数(我们将其称为dllX,dllY和dllZ).如果其他人想使用dllA,他们也需要dllX,Y和Z的副本.

I'm creating a DLL (let's call this dllA), which, in turn, calls functions in other DLLs (let's call these dllX, dllY and dllZ). If someone else wanted to use dllA, they'd need a copy of dllX, Y and Z as well.

有没有一种方法可以生成dllA,以便将dllX,Y和Z中所需的功能链接到dllA中?我不知道这是否是正确的术语,但这叫做静态链接DLL"吗?

Is there a way to build dllA such that the needed functions in dllX, Y and Z get linked into dllA? I don't know if this is the right terminology, but is this called "statically linking a DLL"?

我正在寻找一个简单的解决方案.如果简单地将dllX,Y和Z串联在一起,然后以某种方式将其附加到dllA,我会感到满意.但是我有一种不好的感觉,对此没有简单的解决方案.

I'm looking for a simple solution. I'd be happy with something crude that simply concatenates dllX, Y and Z and appends that to dllA somehow, if such a thing exists. But I have this bad feeling that there's no easy solution to this.

我在Windows上使用VS.

I'm on Windows, using VS.

谢谢!

推荐答案

您不能静态链接DLL,只能静态链接LIB.DLL是自包含的,具有静态成员和DllMain加载/卸载依赖关系,这意味着它们无法拆分为包含函数并链接为其他可执行文件.

You can't statically link a DLL, only a LIB. DLLs are self contained and have static members and DllMain load/unload dependencies that means they cannot be split into containing functions and linked into a different executable.

您应根据需要创建一个部署所有适当dll的安装程序.

You should create an installer that deploys all the appropriate dlls, as needed.

如果您真的认为这很重要,并且不能依靠应用程序安装程序,则可以创建一个包装器,将所需的dll(A,X,Y和Z)嵌入为资源,并在运行时提取它们并将其写入磁盘用户配置文件的temp文件夹,然后加载提取的dllA并将所有传入的函数调用推迟到加载的dllA.某些sysinternals工具使用类似的技术从x86映像中提取应用程序的x64映像,并重新启动为64位进程,而无需附带两个单独的exe.

If you really think is that important and you cannot rely on your app installer you can create a wrapper that embeds the needed dlls (A, X, Y and Z) as resources and at runtime extracts them and write them to disk in the user profile temp folders, then loads the extracted dllA and defers all incoming function calls to the loaded dllA. Some of the sysinternals tools used similar techniques to extract x64 images of the application from the x86 image and relaunch themselves as 64bit processes w/o having to ship two separate exes.

这篇关于在Windows中静态链接DLL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆