谁有Linux,快来玩一把,写个测试报告,发到咱们的电子杂志上
来源:岁月联盟
时间:2003-07-12
Getting Started With C# On Linux
By Rob Blackwell(rob.blackwell@aws.net)
When Microsoft launched its .NET strategy, one of the objectives was to allow software to be written for a variety of different platforms. It submitted .NET to ECMA for standardization and many people now consider it to be more "open" and accessible than the Java platform.
Miguel de Icaza, the founder of Ximian is working on Mono - an open source implementation of the .NET framework which runs under Linux.
If, like me, you work with Microsoft technologies, but also tinker with Linux, then you can now write C Sharp programs which run on both platforms. This article takes a brief look at Mono and explains how to install the software and start some simple programming.
Head over to www.go-mono.com and download the latest packaged version of Mono. At the time of writing this is mono-0.10.tar.gz
Before you try to build Mono, you need to make sure that you have fairly new versions of the GIMP Toolkit and Drawing Kit, as well as pkg-config. I have a RedHat 7.2 system and I still had to download and upgrade these packages. You can get them from rpmfind.net and install them as follows:
# rpm -Uvh glib2-2.0.0-1.i386.rpm# rpm -Uvh glib2-devel-2.0.0-1.i386.rpm# rpm -Uvh pkgconfig-0.12.0-1.i386.rpmThe next step is to unpack the Mono distribution file like this:
# tar -zxvf mono-0.10.tar.gz
To install Mono, change into the newly created mono-0.10 directory and type
# ./configure# make# make installIf all goes well, then you should now have a working Mono system including mcs (The Mono C Sharp Compiler suite) , mono (The Mono Just in Time compiler) and mint (The Mono interpreter). All of which now have useful man pages.
Tradition dictates that the first program we should try out is the famous Hello World, and here it is coded in C Sharp.
// Hello World in C Sharpclass Hello { static void Main() { System.Console.WriteLine("Hello World"); }}C Sharp programs must end in the .cs suffix. Type this file in (using your favourite text editor) and save it to a file Hello.cs then you can compile it using the following command
# mcs Hello.cs
If you've typed everything correctly and there are no syntax errors, this should generate a MSIL file called Hello.exe which you can try out as follows:
# mint Hello.exeHello WorldThe mint interpreter has a number of options including --trace and --debug which are useful for debugging. When your program is finished, you can run it with the JIT compiler to get full performance.
# mono Hello.exeHello WorldThe Common Language Runtime provides cross-platform portability. A .NET application can run on any system for which the CLR has been ported. In fact Mono version 0.10 is the first version to be "self hosting" before that, the Mono C Sharp compiler had to be compiled using the Microsoft .NET Framework SDK on Windows and then moved over to Linux. You can take C Sharp programs compiled on Windows and run them on Linux, but at the time of writing there are still a few problems going from Linux to Windows.
Building GUI applications under Mono is still difficult, but work is underway. The Gtk# project at gtk-sharp.sourceforge.net aims to provide C# language bindings for the gtk+ toolkit. The aim is also to provide a Windows.Forms compatible library under Mono. There are several areas, where moving from Microsoft platforms to Linux may be hard, in particular where Microsoft rely on win32 extensions, HWND and HDC handles etc, but much of this has already been thought through by the team.
Mono is not yet a full implementation of the .NET framework, but there is enough there to start writing some interesting programs. New releases are likely to come thick and fast, and the breadth and quality of the base classes will continue to improve.
Miguel de Icaza has hinted at using Mono for GNOME development. Maybe Mono and .NET will help to bring the open source and Microsoft development communities closer together?
Useful Siteswww.go-mono.com The home of the Mono projectmsdn.microsoft.com/net Microsoft .Net Developmentwww.aws.netActive Web Solution