如何静态链接.DLL? [英] How to link a .DLL statically?

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

问题描述

我们有一个(纯本地C ++).DLL由VS构建。作为客户端,我们有一些本机C ++应用程序和用C ++ / CLI编写的.Net-Wrapper。最后有一些客户端应用程序的.Net-Wrapper用C#编写。

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#应用​​程序工作正常我必须将其复制到每个可执行文件目录或放在somath%%PATH%(这将避免在开发人员电脑,因为他们可能想启动不同的应用程序与不同的版本DLL)。
如果有UserControls引用Wrapper-DLL,则会出现更大的问题:您必须将DLL复制到VS的目录或再次复制到%PATH%。
但是最糟糕的情况发生在我们的翻译工具。此工具跟踪.Net程序集,并将其打包到可以发送到外部翻译程序的翻译程序包中。据我所知,没有办法把原生的.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会解决我的问题。
但是对于我们的Native应用程序,这个本地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.

所以我有两个选项:


  • 创建两个项目(一个生成静态库;一个创建一个动态库> =我试图避免这种情况)

  • 找到一个解决方案来静态链接DLLs

  • 找到一种让VS从一个项目生成两个输出的方法

推荐答案

在dll的C ++项目文件中,创建两个配置,一个生成DLL,一个生成.lib。两个项目不是必需的,因为任何.NET / C ++项目都可以支持多个构建配置(这是版本和调试版本的构建方式不同)。

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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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