你能链接你的 C++使用 .obj 的项目依赖项(并创建一个 dll)?
我在 VS 2008 中有一个 C++/CLI 项目,它直接依赖于本机 C++ 库,而该库又具有四个额外的本机 C 和 C++ 库依赖项;其中一些依赖项目也相互依赖。我拥有所有库的源代码,并且可以将它们全部成功构建为单独的库,但我不想分发大量程序集,而是真正希望将它们全部合并到包含我的托管和非托管代码的单个 dll 中。
依赖项目相当大(约 2000 个源文件和头文件),因此将它们合并到“超级项目”中有点笨拙。鉴于我读过的一些博客文章和文章,似乎确实可以将它们全部链接在一起;到目前为止,我面临的挑战是缺乏实际尝试此操作的任何人的文档或第一人称叙述。
这是可以合理完成的事情吗?如果没有,我应该考虑哪些替代方案?构建和/或链接过程中是否有需要考虑的策略?
I have a C++/CLI project in VS 2008 that has a direct dependency on a native C++ library that, in turn, has four additional native C and C++ library dependencies; some of these dependent projects rely on each other as well. I have source code for all of the libraries and can build them all successfully as separate libraries, but instead of having a multitude of assemblies to distribute, I would really like to consolidate all of them into a single dll containing my managed and unmanaged code.
The dependency projects are rather large (~2000 source and header files) so merging them into a 'super-project' is a bit unwieldy. Given some of the blog posts and articles I've read it does seem possible to link them all together; my challenge thus far has been the lack of documentation or first-person accounts of anyone actually trying this.
Is this something that can reasonably be done? If not, what alternatives should I consider? Is there a strategy in the building and/or linking process(es) that needs to be considered?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为这不是一件特别琐碎的事情。当然,没有任何链接器开关可以用来神奇地将 DLL 组合成一个,因此您没有太多选择,只能创建一个或多个新项目。您还可能会遇到一些问题,例如命名空间冲突和不同的编译器指令。您还必须以某种方式将所有五个 DLL 的入口点合并到最终的 DLL 中。
I don't think this is a particularly trivial thing to do. There certainly isn't some linker switch you can use to magically combine the DLLs into one, so you don't have much choice but to create a new project or projects. There are also a few issues you may encounter, such as namespace collisions and differing compiler directives. You'll also have to merge the entry points for all five DLLs somehow in your final DLL.
我认为既然你谈论的是单独的库,那么你指的是 DLL。由于您拥有源代码并且可以构建它们,因此您可以添加静态库的构建输出。然后所有静态库都将链接到最终的 C++/CLI 程序集 dll 中。
我已经用原生 C++ 做了很多这样的事情 - 将逻辑放入静态库中,添加一个“真正的”dll 用于分发,以及一个单元测试 exe 用于测试。我不明白为什么相同的模式不适用于 C++/CLI。
I assume since you are talking about separate libraries you mean DLLs. Since you have the source and can build them, you could add a build output of static library. Then all the static libraries would be linked into your final C++/CLI assembly dll.
I've done this quite a bit with native C++ - put the logic into a static library, add a "real" dll for distribution, and a unit test exe for testing. I don't see why the same pattern won't work for C++/CLI.