Running C # on Linux

Source: Internet
Author: User
Tags gtk linux text editor

As we all know, C # is a Microsoft-launched. NET language that runs only on the. NET platform, such as the win 9x, ME, NT, 2000, XP, and win CE operating systems. But now there is a project called Mono, whose goal is to put. NET and its programming language to a non-Windows platform. C # is now the only. NET language that is ported to a non-Windows platform.

On any platform (operating system + hardware), the three most fundamental requirements for writing and running a program are libraries, compilers/interpreters, and operating environments. Libraries provide common routines in the form of classes and methods (functions), simplifying the writing of large programs. NET Framework is no exception, including many class libraries. In addition, the compiler and runtime environment are essential when converting programs to executable form and running execution files. The mono package contains a part of the. NET class library, a C # compiler, and a. NET runtime Environment CLR (Common Language Runtime, Common language runtime Environment).

Mono claims to support Linux, Solaris, free BSD, and Ms Windows, and it is said to support SPARC, PowerPC, and StrongARM processors in addition to the Intel x86 series of CPUs (486, various types of Pentium, etc.).

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

Command line Application

To download the software from the Mono home page (http://www.go-mono.com/), perform the following command to install all RPMs:

RPM-IVH *.rpm

After the installation is complete, all the basic dynamic execution libraries, including System.Data.dll, System.dll, System.Drawing.dll, System.Web.dll, and System.Xml.dll, are copied to/usr/lib. Next, enter the following in the Linux text editor to save the file as HelloMono.cs:

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

Execute the following command to compile the C # file:

MCS HelloMono.cs

MCS is the C # command-line compiler for mono. Similar to the CSC compiler for the MS. NET SDK, MCS also has a number of command-line options. The above command will generate the executable file HelloMono.exe. Note that this execution file is not a Linux execution file, but rather a. NET executes the file, or the executable code of the file is in the intermediate language (Il,intermediate Language). To run this execution file, you must execute the following command:

Mono HelloMono.exe
"Hello Mono" will be displayed on the Linux console. For more instructions on MCS and Mono, please follow the man MCs or man mono reference to their man document.

GUI applications

Mono does not support Windows Forms, but GTK #编写GUI is available in C # programming . C # support tool for GTK #是GTK + graphics library, available for download from http://gtk-sharp.sourceforge.Net/. When the download is complete, install the RPM first:

RPM-UVH *.rpm--nodeps
Untie gtk-sharp-0.2.1.tar.gz:
TAR-ZXVF gtk-sharp-0.2.1.tar.gz
Go to subdirectory gtk-sharp-0.2.1, execute:
./configure--PREFIX=/USR
make
Make install

After you complete this step, restart again. All dynamic code modules associated with gtk# (Gtk-sharp.dll, Atk-sharp.dll, Gdk-sharp.dll, Glib-sharp.dll, and Pango-sharp.dll) are copied to the/usr/lib directory. When compiling a C # program that uses gtk# to produce a GUI, they must be referenced through the-R parameter. The gtk# download package contains several sample programs, such as HelloWorld.cs, Menu.cs, ButtonApp.cs, and so on. The commands to compile these files are 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

Here's a look at how to refer to the previous. dll dynamic modules with the-r option. Execute the STARTX command to start the X window, go to the terminal window, and then go to the directory where the sample program is located, and execute the following commands to run each program individually:

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

The mono project is still being perfected and developed, and has not been fully ported. NET class. But anyway, it will be good news for many people. For information about the progress of the Mono C # class Library migration, visit www.go-mono.com/class-status. HTML.

Consider a typical server/client type. NET application: End users only deal with clients, the client is preferably a convenient GUI application, many people will also want to use the familiar Windows platform. However, for them, server-side use of Windows or Linux is completely unrelated. Therefore, the server side can be used with the Linux fabric with mono, saving the investment with dedicated Windows Server. Mono will also facilitate the application migration. If mono develops smoothly, Windows developers will also be able to develop applications for Linux or other non-Windows platforms. If so, a similar visual Studio appears shortly afterwards. NET but a free or inexpensive Linux development IDE is also probably.

However, whether all of this can be a reality depends on whether mono can thrive and depends on how mono is compatible or similar to the. NET Framework on the Windows platform. Other factors are also critical, such as the performance of mono, the friendliness of the GUI, and so on.

Running C # on Linux

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.