简体   繁体   English

是否可以使用Mono AOT编译(本机)c#可执行文件和C#Dll(CIL)(未实现Mono方法)

[英]Is it Possible to use Mono AOT Compiled (Native)c# Executable and C# Dll(CIL) which has unimplemented Mono Methods

I have a main C# executable that can be compiled using Mono c# compiler, but the EXE uses DLLs which uses P/Invoke and other mono unsupported methods so I cannot compile this DLL to Mono. 我有一个主要的C#可执行文件,可以使用Mono c#编译器进行编译,但是EXE使用的DLL使用P / Invoke和其他不支持Mono的方法,因此我无法将此DLL编译为Mono。 Is there any way use these DLLs with Ahead of Time Compiled Mono Executable? 有什么方法可以将这些DLL与提前编译的Mono可执行文件一起使用吗?

Your question is a little vague, because it seems that you're conflating AOT and P/Invoke. 您的问题有点含糊,因为您似乎正在混淆AOT和P / Invoke。 AOT won't call and cache the results of a P/Invoke call, in fact, they have nothing to do with each other. AOT不会调用并缓存P / Invoke调用的结果,实际上,它们彼此无关。

AOT basically generates native code for the ILDASM .NET bytecode. AOT基本上为ILDASM .NET字节码生成本机代码。 It has nothing to do with P/Invoke calls. 它与P / Invoke调用无关。 P/Invoke is a runtime .NET function that calls the function from the native DLL. P / Invoke是运行时.NET函数,它从本机DLL调用该函数。

Contrary to your post, Mono fully supports P/Invoke. 与您的帖子相反,Mono完全支持P / Invoke。 Your problem isn't with Mono, hence there's nothing that Mono AOT can do to resolve your issue. 您的问题不在Mono上,因此Mono AOT无法解决您的问题。 Your problem is that the library being P/Invoke'd is not supported on the platform you're running your application under Mono on. 您的问题是在Mono on下运行应用程序的平台上不支持P / Invoke'd库。 No one can help you here; 没有人可以在这里为您提供帮助; you will need to either reimplement the native functions for the new platform or find a managed alternative. 您将需要为新平台重新实现本机功能,或者找到托管替代品。

Yes, it is possible to AOT-compile the main executable and still access non-AOT-compiled libraries. 是的,可以对主要可执行文件进行AOT编译,而仍然可以访问非AOT编译的库。

But AOT is not meant to be an obfuscation mechanism, in particular you still need the original main executable, otherwise your program won't run. 但是AOT并不是一种混淆机制,特别是您仍然需要原始的主要可执行文件,否则您的程序将无法运行。 The only reason you'd want to AOT-compile an executable/library, is to make it a little tiny bit faster in a few very specific scenarios. 您要AOT编译可执行文件/库的唯一原因是,在某些非常特定的情况下,使其稍微快一点。

If you want to obfuscate, have a look at mkbundle . 如果要混淆,请查看mkbundle

Mono supports pinvoke (If it didnt' it would be nearly useless). Mono支持pinvoke(如果没有,则几乎没有用)。 AOT compiled code can still call pinvoke methods. AOT编译的代码仍然可以调用pinvoke方法。 The problems you will see will come from the unmanaged C libraries that may not be supported on your target platform ( linux? mac? solaris? ) 您将看到的问题将来自目标平台可能不支持的非托管C库(Linux?mac?solaris?)

You have three things here: 您在这里有三件事:

The first two are fully explained in the links above, PInvoke is quite core to advanced .Net/Mono programming and is well supported. 前两个链接在上面的链接中进行了详细说明,PInvoke是高级.Net / Mono编程的核心,并且得到了很好的支持。 AOT is used more often in the Android or IPhone targets AOT在AndroidiPhone目标中更常使用

The final point, where the libraries you have are only available on windows under .Net usually involves core framework methods that Mono does not implement ( what are you trying to call? ) or are wrappers around windows system calls ( often in to kernel32.dll ) that don't exist on linux or other platforms. 最后一点,您拥有的库仅在.Net下的Windows上可用,通常涉及Mono不会实现的核心框架方法(您要调用的是什么?)或Windows系统调用的包装器(通常在kernel32.dll中) )在Linux或其他平台上不存在。

You may find also that even if the assemblies you need appear to run on mono that the original author may not have paid attention to things like using portable directory separator characters and that have always assumed a windows platform. 您可能还会发现,即使您所需的程序集似乎在mono上运行,原始作者也可能没有注意使用可移植目录分隔符之类的东西,并且始终假定使用Windows平台。

My advice would be to run a new copy of MoMa on your program and see what it says. 我的建议是在您的程序上运行MoMo的新副本,然后查看其内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM