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/