c# - Mono Mkbundle 是否生成 native 代码

标签 c# mono monodevelop xamarin-studio

Mono 生成的普通 EXE 在 IL 中。我想生成 native 可执行文件,使用 mkbundle 生成 native Exe 还是应该使用 Mono AOT。

最佳答案

是的,mkbundle 生成 native 可执行文件。 例如,在 Linux 上,这是我的 .NET 程序集:

file Agent.exe
Agent.exe: PE32 executable (console) Intel 80386, Mono/.Net assembly, for MS Windows

我告诉 mkbundle 将其编译为 native 可执行文件(在这里我必须添加 Common.dll,它是我的 Agent.exe 程序集的依赖项):

mkbundle --deps -o Agent Agent.exe Common.dll
   OS is: Linux
   Sources: 3 Auto-dependencies: True
   embedding: Agent/bin/Debug/Agent.exe
   embedding: Agent/bin/Debug/Common.dll
   embedding: /usr/lib/mono/4.5/mscorlib.dll
   embedding: /usr/lib/mono/gac/System.Runtime.Serialization/4.0.0.0__b77a5c561934e089/System.Runtime.Serialization.dll
   embedding: /usr/lib/mono/gac/System.Xml/4.0.0.0__b77a5c561934e089/System.Xml.dll
   embedding: /usr/lib/mono/gac/System/4.0.0.0__b77a5c561934e089/System.dll
   embedding: /usr/lib/mono/gac/Mono.Security/4.0.0.0__0738eb9f132ed756/Mono.Security.dll
   embedding: /usr/lib/mono/gac/System.Configuration/4.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
   embedding: /usr/lib/mono/gac/System.Security/4.0.0.0__b03f5f7f11d50a3a/System.Security.dll
   embedding: /usr/lib/mono/gac/System.Core/4.0.0.0__b77a5c561934e089/System.Core.dll
   embedding: /usr/lib/mono/gac/Mono.Posix/4.0.0.0__0738eb9f132ed756/Mono.Posix.dll
   embedding: /usr/lib/mono/gac/System.Data.Linq/4.0.0.0__b77a5c561934e089/System.Data.Linq.dll
   embedding: /usr/lib/mono/gac/System.Data/4.0.0.0__b77a5c561934e089/System.Data.dll
   embedding: /usr/lib/mono/gac/Mono.Data.Tds/4.0.0.0__0738eb9f132ed756/Mono.Data.Tds.dll
   embedding: /usr/lib/mono/gac/System.Transactions/4.0.0.0__b77a5c561934e089/System.Transactions.dll
   embedding: /usr/lib/mono/gac/System.EnterpriseServices/4.0.0.0__b03f5f7f11d50a3a/System.EnterpriseServices.dll
Compiling:
as -o temp.o temp.s 
cc -ggdb -o Agent -Wall temp.c `pkg-config --cflags --libs mono-2`  temp.o
Done

Now, Let's run the file command again, this time against the generated 'Agent' binary:

file Agent
Agent: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, BuildID[sha1]=698384c13208eccc609e5a573deeb09ed3420a29, not stripped

注意:这个 native 二进制文件仍然依赖于 libmono(Mono 运行时库),因此它无法在没有安装 Mono 的机器上运行。

然而,您可以将 libmono 嵌入到您的二进制文件中,并通过使用 mkbundle --static 选项获得一个独立的、自包含的可执行文件。

关于c# - Mono Mkbundle 是否生成 native 代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20485834/

相关文章:

来自 monodevelop 的 iPhone 应用程序开发

mono - 运行 MonoTouch 应用程序时出现 SIGABRT 错误

c# - LINQ on 循环条件

c# - 具有大型 .Any() 的 Entity Framework 6 中的 LINQ

c# - 如何从 .NET Core 中的 ContentType(MIME 类型)获取文件扩展名?

Xamarin Studio for Mac 在 FSI 中抛出异常 - `seems` 不加载核心 F# 库

c# - 如何使用 GTK 使 Mono/C# 应用程序保留屏幕空间?

ios - 对静态库的非托管 C# 调用

c# - 将 MSbuild 文件从 4.0 降级到 3.5

c# - 我应该有多个存储库吗?