问题描述
我们有一个由 VS 构建的(纯原生 C++).DLL.作为客户端,我们有一些本地 C++ 应用程序和一个围绕这个 DLL 的 .Net-Wrapper,用 C++/CLI 编写.最后,还有一些用 C# 编写的 .Net-Wrapper 客户端应用程序.
We have a (pure native C++) .DLL that is build by VS. As clients we have some native C++ applications and a .Net-Wrapper around this DLL written in C++/CLI. Finally there are some client applications for the .Net-Wrapper written in C#.
我的问题是 native.dll 必须以与 .Net 世界不同的方式分发,并且 VS 不跟踪该 DLL.因此,为了让我所有的 C# 应用程序正常工作,我必须将它复制到每个可执行目录或将它放在 %PATH% 中的某个位置(我会在开发人员计算机上避免这样做,因为他们可能想要使用不同版本的 DLL 启动不同的应用程序).如果存在引用 Wrapper-DLL 的 UserControl,则会出现更大的问题:您必须将 DLL 复制到 VS 的目录或再次复制到 %PATH%.但最坏的情况发生在我们的翻译工具上.该工具跟踪 .Net-Assemblies 并将它们打包到可以发送给外部翻译器的 Translator-packages 中.据我所知,无法将本机 .DLL 放入该包中!
My problem is that the native.dll must be distributed in a different way than the .Net world works and the VS does not keeps track of that DLL. So to let all my C# Apps work correctly I have to copy it to each executable directory or put it somwhere in %PATH% (which I would avoid on developer computers since they may want to start different apps with different versions of the DLL). Even bigger problems occur if there are UserControls that reference the Wrapper-DLL: You have to copy the DLL to VS's directory or again to %PATH%. But the worst case occurs with our Translator tool. This tool keeps track of .Net-Assemblies and packs them into Translator-packages that can be send to an external translator. As far as I know there is no way to put the native .DLL into that package!
所以我计划将本机 DLL 静态链接到 .Net-Wrapper,这将解决我的问题.但是对于我们的本机应用程序,这个本机 DLL 仍然必须是一个 DLL.
So I plan to link the native DLL statically into the .Net-Wrapper which would solve my problems. But for our Native applications this native DLL must still be a DLL.
所以我有两个选择:
- 制作两个项目(一个生成静态库;一个创建动态库 => 我尽量避免这种情况)
- 找到静态链接 DLL 的解决方案
- 找到一种方法让 VS 从一个项目生成两个输出
推荐答案
在 dll 的 C++ 项目文件中,创建两个配置,一个生成 DLL,一个生成 .lib.两个项目不是必需的,因为任何 .NET/C++ 项目都可以支持多个构建配置(这就是 Release 和 Debug 版本构建的不同方式).
In the C++ project file for the dll, create two configurations, one that generates a DLL and one that generates a .lib. Two projects are not necessary, since any .NET/C++ project can support multiple build configurations (this is how Release and Debug versions build differently).
这篇关于如何静态链接 .DLL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!