Linux Mono 上的 F# 完全静态编译
我希望能够在 Linux 系统 (Debian) 上运行用 F# 编写的代码,但我不太可能在其上安装 Mono。有没有办法将 F# 编译为完全静态并且完全不依赖于 Mono?基本上只是得到一个可执行的二进制文件,我可以像任何其他 Linux 二进制文件一样运行它?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
即使在精简帐户上,您也可以编译自己的 Mono 版本 - 这并不是特别困难,请参阅 http:// /www.mono-project.com/Compiling_Mono。有一些依赖项,但它们并不难找到。不过,您需要在大多数运行调用前加上 mono 前缀,例如
mono myapp.exe
而不是./myapp.exe
Even on a stripped down account you can compile your own version of Mono - it is not particularly hard, see http://www.mono-project.com/Compiling_Mono. There are a few dependencies, but they aren't hard to find. You will need to prefix most of your run calls with mono though, like
mono myapp.exe
rather than./myapp.exe
尝试AOT。但要注意它的局限性。
更新:
我认为我太快地寻求答案了,而且还没有深入到将其变成有用的东西。 AOT 会将代码预编译到共享库中,在适当的条件下这可能会提高性能。
不过,如果您要求根本不在客户端计算机中安装单声道运行时(为什么?),我认为您应该尝试 mkbundle / mkbundle2。这将生成一个巨大的自包含可执行文件(C# Hello World + deps 为我的机器生成了大约 2.5MB 的文件......使用 -z 我得到了大约 900k)。您可以尝试将其与 Linker 结合使用,以进一步去除应用程序所依赖的库中未使用的部分。
至于你的第二个问题,F# 编译器将像任何其他 .NET 编译器一样生成 CIL 。所以,应该没关系。不过,如果您的应用程序包含单声道 AOT 编译器尚不支持的 IL 指令(例如,您需要 mkbundle2 来处理泛型)或对无法安装在 Debian 机器中的外部链接库的依赖项,那么您就很不幸了。我猜你必须自己做一些试错操作。
Try AOT. But be ware of it's limitations.
Update:
I think I've jumped for an answer a bit too fast and haven't dive deep enough to turn it into something useful. AOT will pre-compile code into shared libraries, under the right conditions this may increase performance.
Still, if you have a requirement to not install the mono runtime in the client machine at all (why?), I think you should try mkbundle / mkbundle2. This will produce a huge self contained executable (C# Hello World + deps generated a file around 2.5MB for my machine... With -z I got around 900k). You can try to combine it with Linker to further strip out unused portions of libraries that your application depends on.
As for your second question F# compiler will generate CIL as any other .NET compiler. So, it should not matter. Still, if your application contains either IL instructions that are not yet supported by mono AOT compiler (e.g., you need mkbundle2 to handle generics) or dependencies to external linked libraries that you can't install in your Debian box you are out of lucky. Guess you will have to do a bit of trial and error operations by yourself.