Mono Mkbundle 是否生成本机代码

Does Mono Mkbundle Produce Native Code(Mono Mkbundle 是否生成本机代码)

本文介绍了Mono Mkbundle 是否生成本机代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

mono 生成的普通 EXE 在 IL 中.我想生成 Native Executable,使用 mkbundle 生成原生 Exe 还是应该使用 Mono AOT.

解决方案

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

文件 Agent.exeAgent.exe:PE32 可执行文件(控制台)Intel 80386,Mono/.Net 程序集,适用于 MS Windows

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

<上一页>mkbundle --deps -o Agent Agent.exe Common.dll操作系统是:Linux来源:3 自动依赖:真嵌入:Agent/bin/Debug/Agent.exe嵌入:Agent/bin/Debug/Common.dll嵌入:/usr/lib/mono/4.5/mscorlib.dll嵌入:/usr/lib/mono/gac/System.Runtime.Serialization/4.0.0.0__b77a5c561934e089/System.Runtime.Serialization.dll嵌入:/usr/lib/mono/gac/System.Xml/4.0.0.0__b77a5c561934e089/System.Xml.dll嵌入:/usr/lib/mono/gac/System/4.0.0.0__b77a5c561934e089/System.dll嵌入:/usr/lib/mono/gac/Mono.Security/4.0.0.0__0738eb9f132ed756/Mono.Security.dll嵌入:/usr/lib/mono/gac/System.Configuration/4.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll嵌入:/usr/lib/mono/gac/System.Security/4.0.0.0__b03f5f7f11d50a3a/System.Security.dll嵌入:/usr/lib/mono/gac/System.Core/4.0.0.0__b77a5c561934e089/System.Core.dll嵌入:/usr/lib/mono/gac/Mono.Posix/4.0.0.0__0738eb9f132ed756/Mono.Posix.dll嵌入:/usr/lib/mono/gac/System.Data.Linq/4.0.0.0__b77a5c561934e089/System.Data.Linq.dll嵌入:/usr/lib/mono/gac/System.Data/4.0.0.0__b77a5c561934e089/System.Data.dll嵌入:/usr/lib/mono/gac/Mono.Data.Tds/4.0.0.0__0738eb9f132ed756/Mono.Data.Tds.dll嵌入:/usr/lib/mono/gac/System.Transactions/4.0.0.0__b77a5c561934e089/System.Transactions.dll嵌入:/usr/lib/mono/gac/System.EnterpriseServices/4.0.0.0__b03f5f7f11d50a3a/System.EnterpriseServices.dll编译:as -o temp.o temp.scc -ggdb -o 代理 -Wall temp.c `pkg-config --cflags --libs mono-2` temp.o完毕

现在,让我们再次运行 file 命令,这次是针对生成的代理"二进制文件:

文件代理代理:ELF 64 位 LSB 可执行文件,x86-64,版本 1 (SYSV),动态链接(使用共享库),适用于 GNU/Linux 2.6.32,BuildID[sha1]=698384c13208eccc609e5a573deeb09ed3420a29,未剥离

注意:这个原生二进制文件仍然依赖于 libmono(Mono 运行时库),所以它不能在没有安装 Mono 的机器上工作.

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

The normal EXE's generated by mono are in IL.I want to generate Native Executable,does using mkbundle produce native Exe's or should i use Mono AOT.

解决方案

Yes, mkbundle produces native executables. For example, on Linux, here is my .NET assembly:

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

I tell mkbundle to compile it to a native executable (here I have to add Common.dll which is a dependency to my Agent.exe assembly):

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

Note : this native binary still depends on libmono (the Mono runtime library), so it won't work on a machine without a working Mono installation.

You can however embed libmono into your binary and get an independant, self-contained executable by using mkbundle --static option.

这篇关于Mono Mkbundle 是否生成本机代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:Mono Mkbundle 是否生成本机代码

基础教程推荐