Run C # on Linux

xiaoxiao2021-03-06  90

C # is the .NET language launched by Microsoft, can only run on the .NET platform, such as the operating system such as WIN 9X, ME, NT, 2000, XP, and WIN CE. However, now there is a project called Mono, its goal is to transplant the .NET and its programming language to non-Windows platforms. Now, C # is the only .NET language that is ported to a non-Windows platform.

On any platform (operating system hardware system), the three most fundamental requirements of writing and running the program are libraries, compiler / interpreters, and running environments. The library provides a commonly used routine in the form of classes and methods (functions) to simplify the writing of large programs. The .NET framework is no exception, including many class libraries. In addition, the compiler and the operating environment are essential to convert the program into an executable form and run the execution file. The MONO package contains a part of the .NET class library, a C # compiler, and .NET running environment CLR (Common Language Runtime, public language runtime environment).

Mono claims to support Linux, Solaris, Free BSD, and MS Windows; except the Intel X86 series of CPUs (486, all kinds of Pentium, etc.), it is said to support SPARC, PowerPC, and Strongarm processors.

Let's take a look at how to run Mono on Linux.

Command line application

First from Mono homepage (

Http://www.go-mono.com/) Download the software, perform the following command to install all RPM:

RPM-IVH * .RPM

After the installation is complete, all basic dynamic execution libraries include system.data.dll, system.dll, system.drawing.dll, system.web.dll, and system.xml.dll are copied to / usr / lib. Next, enter the following content in the Linux text editor, save the file as Hellomono.cs:

Class Hellomono

{

Public static void main (string [] args)

{System.Console.writeline ("Hello Mono");

}

}

Perform the following command to compile C # files:

MCS Hellomono.cs

MCS is Mono's C # command line compiler. Similar to the MS .NET SDK's CSC compiler, MCS also has a lot of command line options. The above command will generate an executable Hellomono.exe. Note that this execution file is not a Linux execution file, but a .NET execution file, or, this file's executable code form is an intermediate language (IL, Intermediate Language). To run this execution file, you must do the following command:

Mono Hellomono.exe

"Hello Mono" will be displayed on the Linux console. For more descriptions of MCS and MONO, perform the Man MCS or Man Mono to refer to its Man documentation.

GUI application

Mono does not support Windows Forms, but in C # programming can be written in GUI. GTK # is a C # support tool for GTK graphics library,

Http://gtk-sharp.sourceforge.net/ download. After the download is complete, you must install rpm:

RPM -UVH * .rpm --Nodeps

Unpacking gtk-sharp-0.2.1.tar.gz:

Tar -zxvf gtk-sharp-0.2.1.tar.gz

Enter the subdirectory GTK-Sharp-0.2.1, execute: ./ Configure --prefix = / usr

Make

Make Install

After completing this step, restart once. All dynamic code modules (gtk-sharp.dll, attack, gdk-sharp.dll, glib-sharp.dll, glib-sharp.dll, and pango-sharp.dll) are copied to / usr / lib directory. When compiling with GTK # C # programs, they must be referenced by the -R parameter. The GTK # download package contains several sample programs such as HelloWorld.cs, Menu.cs, buttonapp.cs, etc. The command to compile these files is as follows:

MCS -R gtk-sharp -r glib-sharp helloworld.cs

MCS -R gtk-sharp -r glib-sharp -r system.drawing menu.cs

MCS -R gtk-sharp -r glib-sharp -r system.drawing buttonapp.cs

Let's take a look at how to reference each .dll dynamic module through the -R option. Execute the startX command to launch X Window, enter the terminal window, then enter the directory where the sample program is located, perform the following commands, run each program, respectively:

Mono HelloWorld.exe

Mono menu.exe

Mono ButtonApp.exe

The Mono project is still in improved and developing, and all .NET classes are not transplanted. But no matter what, it will be a good news for many people. For information on Mono C # class library transplantation, please visit

Www.go-mono.com/class-status.html.

Consider a typical server / client type .NET application: End users only deal with the client, the client is the best convenient GUI application, many people will want to use the familiar Windows platform. However, for them, the server side is completely independent of Windows or Linux. Therefore, the server side can be constructed with a Linux constructed with MONO, saving investments with dedicated Windows servers. Mono will also be convenient for application migration. If MONO can develop smoothly, Windows developers will also be able to develop applications for Linux or other non-Windows platforms. If this is the case, there is also a similar Visual Studio .NET but free or cheap Linux development IDE may be said.

However, if all this can become a reality, depending on whether MONO can thrive, but also on Mono's .NET framework compatible with the Windows platform. Other factors are also very critical, such as MONO performance, GUI's friendly level.

source:

Sidi Net

转载请注明原文地址:https://www.9cbs.com/read-123350.html

New Post(0)