将多个 DLL 合并为 1
我想知道是否可以将多个 DLL 组合成 1 个。我目前正在开发一个依赖于许多动态链接库的 C++ 项目,因此是否可以将它们组合成 1 个 DLL 文件,如果可以,如何实现我会那样做吗?
I'm wondering if it's possible to combine multiple DLL's into 1. I'm currently working on a C++ project that is dependent on many dynamic link libraries,so would it be possible to combine them into 1 DLL file, and if so, how would I do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
只是将所有 DLL 项目中的所有源文件合并到一个 DLL 项目中吗?
如果您有多个 *.def 文件(每个项目一个),则将它们合并为一个 *.def 文件。
Just combine all the source files from all the DLL projects into a single DLL project?
And if you have multiple *.def files (one for each project) then combine them into a single *.def file.
实际上,不。理论上,如果你非常想要,你可以做一些事情,比如反汇编所有文件,然后将所有单独的文件重新组装成目标文件,然后将这些目标文件重新链接到一个大的 DLL 中。但要使其真正发挥作用通常并非易事——可能会出现符号名称冲突之类的情况,需要大量工作才能解决。一个更清晰的可能性是将所有将 DLL 放入 zip 文件(或任何您喜欢的文件)中,并使用一个小程序将它们解压缩到临时目录,运行主程序,然后从该目录中删除 DLL。不过,这本身有一些问题(例如,如果机器在运行期间崩溃/断电/发生任何情况,则留下文件的副本)。编辑:由于您拥有源代码,因此可以使用它来构建所有将代码放入单个 DLL 中更为合理。在大多数情况下,只需将所有源文件添加到一个项目中,该项目将创建一个 DLL 作为其输出。您可能(很容易)遇到一些符号冲突。如果可以访问源代码,处理此问题的明显方法是将内容放入命名空间中。
Realistically, no. In theory, if you wanted to badly enough you could do something like disassembling all of them, then re-assembling all the separate files into object files, then re-linking those object files into one big DLL. Getting this to actually work would usually be non-trivial though -- there are likely to be things like conflicting symbol names that would require considerable work to get around.A rather cleaner possibility would be to package all the DLLs into a zip file (or whatever you prefer) and have a small program to unzip them to a temporary directory, run the main program, and then erase the DLLs from that directory. This has a few problems of its own though (e.g., leaving copies of the files if the machine crashes/loses power/whatever during a run).Edit: Since you have the source code, using it to build all the code into a single DLL is much more reasonable. For the most part, it's just a matter of adding all the source files to a single project that creates one DLL as its output. You may (easily) run into some symbol conflicts. Given access to the source code, the obvious way to deal with this would be by putting things into namespaces.
这当然不是不可行的。 Dll 格式包含将多个 dll 中的代码和数据合并为一个并对生成的代码进行变基所需的所有信息。
但这不是我能想到的任何工具链的标准功能。
Its certainly not infeasible. The Dll format contains all the information you need to merge the code and data from multiple dlls into one, and rebase the resulting code.
this is not a standard feature of any toolchain I can think of though.