为什么互操作性不能与静态lib文件一起使用 [英] Why interoperability does not work with static lib file

查看:103
本文介绍了为什么互操作性不能与静态lib文件一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我们有非托管的c ++静态库,我想在C#代码中使用.但是当我尝试时它没有用.然后,我尝试在Google上进行搜索,发现无法直接将静态库与C#一起使用,但我没有找到背后的原因,能否请您说明为什么我不能将静态库与C#一起使用.

关于

Hi,

We have unmanaged c++ static library which I wanted to use in C# code. But when I tried it wasn''t working. Then I try to search on Google and came to know it is not possible to directly use static library with C#, but I did not find reason behind it, can you please suggest why I cannot use static lib with C#.

Regards

推荐答案

不,您不能直接从C#访问静态库.您必须使用DLL.静态库意味着该库将与最终应用程序合并. .net中不存在此概念. .net仅支持DLL

在C#中使用静态库的方法是,首先创建一个Managed C ++包装器,该包装器将为其余的Managed World提供外观.正如其他所有人都已评论过的那样,C#仅支持P/Invoke的DLL.

希望可以清除您的查询.
No, you can''t access static libraries directly from C#. You have to use a DLL. Static library means that the library is going to be merged with your final application. This concept doesn''t exist in .net. .net supports DLLs only

The way to use a static library in C# is to first create a Managed C++ wrapper that will provide a facade for the rest of the managed world. As everyone else has already commented, C# only supports DLLs for P/Invoke.

Hope, it clears your query.


除了GanesanSenthilvel的正确答案.

他没有解释为什么.NET不导入.LIB模块,而仅DLL导入.本质上,.LIB文件只是.OBJ文件内容的集合,用于将目标文件保存在单个库"中.答案是:.LIB或.OBJ文件在运行时不存在,只有DLL模块存在.此外,由于历史原因,.LIB文件没有很好地标准化,这是可以解释的,因为它们用作中间文件,并且它们的详细信息对于可执行模块,旧版本或现代版本的兼容性不是至关重要的(DLL是一种可执行模块). )与平台.

—SA
In addition to the correct answer by GanesanSenthilvel.

He did not explain why .LIB modules are not imported by .NET, only DLLs. Essentially, the .LIB files are just collections of the contents of .OBJ file, something to keep the object files in a single "library". The answer is: .LIB or .OBJ file do not exist during run-time, only DLL modules do. Besides, due to historical reasons, .LIB files are not well standardized, which is explainable, because they serve as intermediate files, and their details are not critical for compatibility of executable modules, legacy or contemporary ones (DLL is one kind of executable modules) with the platform.

—SA


这篇关于为什么互操作性不能与静态lib文件一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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