繁体   English   中英

C#中的Mono编译错误

[英]Mono Compilation Error in C#

首先,我从Microsoft网站复制了以下代码:

using System;
namespace HelloWorld
{
    class Hello 
    {
        static void Main() 
        {
            Console.WriteLine("Hello World!");

            // Keep the console window open in debug mode.
            Console.WriteLine("Press any key to exit.");
            Console.ReadKey();
        }
    }
}

这被保存为HelloWorld.cs。很好。

真正的问题开始于我开始编译时。 首先,我尝试使用mcs HelloWorld.cs出现此错误:

bash: mcs: command not found

当我使用mono --aot HelloWorld.cs ,出现以下错误:

Cannot open assembly 'HelloWorld.cs': File does not contain a valid CIL image.

使用Raspbian和Mono Runtime v2.0.50727的RPI 3。

如何获得该程序进行编译?

从尝试安装mono-complete进行调试:

pi@raspberrypi:~ $ sudo apt-get install mono-complete
    Reading package lists... Done
    Building dependency tree       
    Reading state information... Done
    Some packages could not be installed. This may mean that you have
    requested an impossible situation or if you are using the unstable
    distribution that some required packages have not yet been created
    or been moved out of Incoming.
    The following information may help to resolve the situation:

    The following packages have unmet dependencies:
     mono-complete : Depends: mono-runtime (= 5.4.1.6-0xamarin1+raspbian9b1) but 3.2.8+dfsg-10 is to be installed
                         Depends: mono-runtime-sgen (= 5.4.1.6-0xamarin1+raspbian9b1) but it is not going to be installed
                         Depends: mono-utils (= 5.4.1.6-0xamarin1+raspbian9b1) but it is not going to be installed
                         Depends: mono-devel (= 5.4.1.6-0xamarin1+raspbian9b1) but it is not going to be installed
                         Depends: mono-mcs (= 5.4.1.6-0xamarin1+raspbian9b1) but it is not going to be installed
                         Depends: mono-roslyn (= 5.4.1.6-0xamarin1+raspbian9b1) but it is not going to be installed
                         Depends: mono-csharp-shell (= 5.4.1.6-0xamarin1+raspbian9b1) but it is not going to be installed
                         Depends: mono-4.0-gac (= 5.4.1.6-0xamarin1+raspbian9b1) but it is not going to be installed
                         Depends: mono-4.0-service (= 5.4.1.6-0xamarin1+raspbian9b1) but it is not going to be installed
                         Depends: monodoc-base (= 5.4.1.6-0xamarin1+raspbian9b1) but it is not going to be installed
                         Depends: monodoc-manual (= 5.4.1.6-0xamarin1+raspbian9b1) but it is not going to be installed
                         Depends: libmono-cil-dev (= 5.4.1.6-0xamarin1+raspbian9b1) but it is not going to be installed
                         Depends: ca-certificates-mono (= 5.4.1.6-0xamarin1+raspbian9b1) but it is not going to be installed
     mono-runtime : Depends: mono-runtime-sgen (= 3.2.8+dfsg-10) but it is not going to be installed
    E: Error, pkgProblemResolver::Resolve generated breaks, this may be caused by held packages.
  1. 找不到mcs命令,因为错误状态。 它很可能没有安装,或者您的环境PATH不包含它所在的文件夹,以便能够查找和运行它。 有关设置路径的更多信息: Mono编译器不起作用

  2. mono用于运行已编译的程序,因此它将无法正常工作,您必须先对其进行编译。 首先将C#代码编译为中间语言表示形式,通常将其保存为您部署的*.dll文件。 当您使用服务器上的框架实际运行它们时,它们将再次进行实时编译(JIT)。 这使程序可以自动与其运行的确切CPU架构兼容,并进行必要的优化。 如果要提前进行此操作(AOT),则可以获取编译后的输出并使用--aot标志。

  3. 为什么不使用.NET Core? 这是最新的跨平台框架,应在您的Raspberry Pi上正常运行,请使用以下说明: https : //github.com/dotnet/core/blob/master/samples/RaspberryPiInstructions.md

暂无
暂无

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

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