Run C # on Linux #,

Source: Internet
Author: User
Tags linux text editor

Run C # on Linux #,

On any platform (operating system + hardware system), the three most fundamental requirements for program writing and running are libraries, compilers/interpreters, and runtime environments. The Library provides common routines in the form of classes and methods (functions) to simplify the compilation of large programs .. . NET Framework, including many class libraries. In addition, the compiler and runtime environment are essential to convert programs into executable forms and run execution files. The Mono package contains a part of the. NET class library, a C # compiler, And the. NET Runtime environment CLR (Common Language Runtime, Common Language Runtime environment ).

Mono claims to support Linux, Solaris, Free BSD, and MS Windows; in addition to Intel x86 series CPUs (486, various Pentium, etc.), it is also said to support the Intel x86 series CPUs, PowerPC and StrongArm processors.

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

Command Line Application

First download the software from the Mono home page (http://www.go-mono.com/) and execute the following command to install all RPM:

Rpm-ivh *. rpm

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

Class HelloMono
{
Public static void Main (string [] args)
{System. Console. WriteLine ("Hello Mono ");
}
}

Run the following command to compile the C # file:

Mcs HelloMono. cs

Mcs is the C # command line compiler of Mono. Similar to the csc compiler of the MS. net sdk, mcs also has many command line options. The authorization command will generate the executable file hellomono.exe. Note that this execution file is not a Linux execution file, but a. NET execution file, or the executable code form of this file is the Intermediate Language (IL, Intermediate Language ). To run this execution file, you must execute the following command:

Mono HelloMono.exe
"Hello Mono" is displayed on the Linux console ". For more information about mcs and Mono, Run man mcs or man mono to refer to its man document.

GUI applications

Mono does not support Windows Forms, but GTK # can be used to compile the GUI in C # programming. GTK # Is the C # support tool for GTK + graphics library. It can be downloaded from http://gtk-sharp.sourceforge.net. After downloading, install RPM:

Rpm-Uvh *. rpm -- nodeps
Open gtk-sharp-0.2.1.tar.gz:
Tar-zxvf gtk-sharp-0.2.1.tar.gz
Go to the subdirectory gtk-sharp-0.2.1 and execute:
./Configure -- prefix =/usr
Make
Make install

After completing this step, restart once. All dynamic code modules related to GTK # (gtk-sharp.dll, atk-sharp.dll, gdk-sharp.dll, glib-sharp.dll, and pango-sharp.dll) will be copied to the/usr/lib directory, when compiling a C # program using GTK # To create a GUI, you must reference them using the-r parameter. GTK # The downloaded package contains several sample programs, such as HelloWorld. cs, Menu. cs, and ButtonApp. cs. 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

Next let's take a look at how to reference the previous. dll dynamic modules through the-r option. Run the startx command to start X Window, enter the terminal Window, enter the directory where the sample program is located, and run the following commands to run each program:

Mono HelloWorld.exe
Mono Menu.exe
Mono ButtonApp.exe

The Mono project is still under improvement and development, and all. NET classes have not been transplanted. But in any case, it will be good news for many people. For information about the migration progress of Mono C # class library, visit www.go-mono.com/class-status.html.

Consider a typical server/client. NET application: the end user only deals with the client. The client is preferred for convenient GUI applications, and many may want to use a familiar Windows platform. However, for them, the use of Windows on the server is completely irrelevant. Therefore, the server can be constructed using a Linux with Mono, saving investment in providing dedicated Windows servers. Mono also facilitates application migration. If Mono can develop smoothly, Windows developers will be able to develop applications for Linux or other non-Windows platforms. In this case, a Linux development IDE similar to Visual Studio. NET will not be available soon.

However, whether all of this can become a reality depends on Mono's robust development and on Mono's compatibility or similarity with the. NET Framework on Windows platforms. Other factors are also critical, such as Mono performance and GUI friendliness.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.