删除 MFC DLL 项目的外部依赖项

发布于 2024-09-25 09:56:18 字数 531 浏览 0 评论 0原文

我正在 VS2008 中开发一个 MFC DLL 项目。 该 dll 编译正常,我可以从承包商为我开发的 GUI exe 中调用它。我的 dll 需要安装 Visual C++ Redistributables(也许还有用 C++ 开发的 exe)

另一家公司想要许可我的 dll 与他们的 C++ exe 一起使用。他们要求我的 dll 没有外部依赖项。是否可以编译我的 dll 以删除所有外部依赖项(例如 Visual C++ Redistributables)?

设置 /MT 可以做到这一点吗? 我已阅读 我应该使用 /MD 还是 /MT 进行编译?有一定道理,但我担心 dll 地狱。

这会导致 exe 调用我的 dll 出现问题吗?我在某处读到,exe 和 dll 需要使用相同的 Visual C++ Redistributables 或其他东西。

我对 C++ 有点陌生。任何建议表示赞赏。

Im developing a MFC DLL project in VS2008.
The dll compiles OK and I can call it fine from an GUI exe that a contractor has developed for me. Visual C++ Redistributables are required to be installed for my dll (and maybe the exe which is developed in C++ too)

Another company wants to licence my dll to use with their C++ exe. They have requested that my dll have no external dependencies. Is it possible to compile my dll to remove all external dependencies like the Visual C++ Redistributables?

Does setting /MT do this?
I have read Should I compile with /MD or /MT? which makes some sense but I am concerned about dll hell.

Can this create issues with exe calling my dll? I read somewhere about that the exe and dll need to be using the same Visual C++ Redistributables or something.

I am somewhat new to C++. Any advice appreciated.

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

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

发布评论

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

评论(2

萌梦深 2024-10-02 09:56:18

您可以链接到 CRT 的静态版本(是的,/MT),但这非常危险。您必须仔细检查您的出口。确保它们都不会返回 C++ 对象,甚至不会返回 std::string (或 CString)。或者客户端代码必须释放的任何指针。这会出现严重错误,因为客户端将拥有自己的 CRT 副本并使用不同的堆。这将泄漏返回的对象/指针,当 Vista 和 Win7 的安全堆管理器检测到指针不属于堆时,程序将崩溃。

“外部依赖”到底意味着什么可能是一个有争议的问题。对 CRT 的依赖并不完全是外部的。但是,您必须向他们提供在他们使用的同一版本的 Visual Studio 上构建的 DLL 版本。只有版本匹配时才能共享 CRT。

You can link with the static version of the CRT (yes, /MT) but it is quite dangerous. You'll have to carefully review your exports. Make very sure that none of them return C++ objects, not even an std::string (or CString). Or any pointers that the client code has to release. This will go wrong badly because the client will have its own CRT copy and use a different heap. That will leak the returned object/pointer, crash the program on Vista and Win7 when their secure heap manager detects that the pointer doesn't belong to the heap.

It might be a matter of debate what exactly an 'external dependency' means. Having a dependency on the CRT is not exactly external. You will however have to supply them with a version of the DLL that was built on the same version of Visual Studio that they use. The CRT can only be shared if the version matches.

分分钟 2024-10-02 09:56:18

为什么不将所有依赖的 dll 打包成一个安装程序包并发布给您的客户呢?

我看到有些软件包确实包含了vc的依赖库....

Why not you package all the dependent dlls into a installer package and release to your customer?

I have seen some of the software package does include the vc's dependent libraries....

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