Write Standards$Compliant C Programs in Linux with Dotgnu

Write Standards$Compliant C Programs in Linux with Dotgnu

:FM<IJKFIP DotGNU Ni`k\jkXe[Xi[j$Zfdgc`Xek:gif^iXdj`eC`elon`k_;fk>EL J@E>@E>J?8IG Write C# programs in Linux with the free and vendor-neutral DotGNU. DotGNU, the emphasis is on standards compliance and staying free of license BY MAYANK SHARMA restrictions, rather than on being com- patible with the latest from the Microsoft ike many, I grew up programming programming language are codified as camp. As DotGNU developer Klaus Tre- in C and C++ before moving ECMA (a non-profit standards body) and ichel points out, it is unfair to compare Cinto LAMP-land and Python, Perl, ISO international standards, which cre- DotGNU with Mono because Mono has and PHP. But like that first car, first date, ates the possibility for independent im- full-time developers paid by a large com- and first paycheck, everyone has a spe- plementations. The DotGNU project was pany. DotGNU has always been a volun- cial memory of the first time they com- started with huge fanfare to bring stan- tary project supported with donations. piled gibberish into executable machine dards-compliant C# to Linux. Over the One such donation was from Trumpf code. years, DotGNU has received less atten- Group, which has a pulsed laser cutting Thanks to GCC, open source develop- tion than the other .NET for Linux: the tool that uses DotGNU. The touch screen ers have never had any issues writing C Novell-sponsored Mono project. Never- user interface of the laser tool was built or C++ code on a Linux platform. theless, the project is still chugging through the use of DotGNU. However, when Microsoft announced along, and it is even finding some use in Although some parts of the Mono en- their .NET initiative and the intention to commercial applications. vironment (including the C# compiler) focus their efforts around C#, few people Although DotGNU has lost some of its are released under the GPL, other parts expected Microsoft to release a Linux cli- steam in recent years, it is still in active are subject to license and patent con- ent for their “platform-independent” de- development. Certainly one cannot com- cerns that reflect the complex business velopment tool. pare the pace of development with that relationships between Novell and Micro- Fortunately, .NET’s Common Lan- of Mono – or even with its own initial soft. Fortunately for us, then, the Dot- guage Infrastructure (CLI) and the C# activity – but that’s mainly because, at GNU project offers a vendor-indepen- 22 ISSUE 102 MAY 2009 DotGNU :FM<IJKFIP For writing web services, DotGNU re- brary, which is used to build GUIs. Sys- lies on the DotGNU Execution Environ- tem.Windows.Forms simplifies develop- ment, or DGEE, and phpGroupWare. ment by reducing dependence on other DGEE is a web-service server that can toolkits. accept and process XML-RPC requests from web services, and it can generate >\kk`e^k_\Kffcj browsable documentation for these ser- Some distro repositories carry DotGNU vices in HTML or XML. phpGroupWare binaries, but it’s a good idea to compile is a groupware suite that also provides them from source. The tarballs are avail- a host of web-service components. able on the DotGNU website [1], and The DotGNU C# compiler also com- you can also fetch them via CVS. piles programs written in C, thanks to To get the compiler and libraries, in- the libc implementation of the C com- stall treecc, pnet, and the pnetlib pack- piler, pnetC. Because DotGNU’s objective ages. Optionally, the ml-pnet package is to follow the standards, rather than lets you work with Mono’s libraries, and follow Microsoft, the implementation the pnetC package enables the DotGNU lacks a few assemblies. To help develop- compiler to compile C programs. ers use the missing bits, the DotGNU The command: folks distribute some of the libraries from the Mono project. This distribution cvs -z3 -d:pserver:anonymous5 of the Mono libraries is achieved via the @cvs.sv.gnu.org:/sources/5 build scripts in the ml-pnet package. dotgnu-pnet co . N_pGif^iXdn`k_ downloads the latest source of all Dot- ;fk>EL6 GNU packages inside the directory it is One of the main reasons for writing C# issued from, so make sure it is under code in DotGNU is that it is compatible something like /opt/dotgnu. Now change with the EMCA standards for C# and the to each directory and run ./auto_gen.sh CLI. Furthermore, DotGNU also is com- for all the packages to generate the con- patible with Microsoft’s own CLI imple- figuration and make files. Once that’s mentation of the .NET framework. completed, or if you just grabbed the tar- Thanks to the modular design of Por- ball instead of checking out via CVS, the table.Net, the DotGNU C# compiler can usual ./configure, make, make install run on multiple platforms. Portable.Net’s (the last one, as usual, as root) will in- run-time engine and the C# class library stall the DotGNU compiler and libraries. have extensive support for embedded dent alternative for open source pro- system profiles and can be built with dif- Nfib`e^n`k_k_\:fdg`c\i grammers who want to try their luck ferent ECMA profiles. Each profile en- For those who speak binary, DotGNU with C# and .NET. ables or disables features in the system. works by transforming bytecode into a As a testament to its portability, one of simple instruction set that is passed on 9i\Xb`e^;fne;fk>EL the founding develop- DotGNU is more than just a C# compiler, ers, Gopal Vijayaragha- Listing 1: Hello.cs but I’ll start off with that. Portable.Net is van, was able to get 01 using System; the free implementation of .NET, and it Portable.Net running 02 public class HelloWorld contains a run-time engine, a C# com- on the Indian hand-held 03 { piler, and a host of other tools that make computer, the Encore 04 public static void Main (string [ ] args) Portable.Net easy to port to other plat- Simputer, during the 05 { forms. All these components are written three days of FOSS.IN 06 if (args.Length != 1) in C. The aim of the project is to make in Bangalore. 07 { the development of .NET apps easy on Programmers also non-Microsoft platforms. will appreciate the self- 08 Console.Error.WriteLine("You must tell me your name."); In the early days of development, the contained nature of 09 Environment.Exit(-1); C# system library was split from the DotGNU and that it 10 } main Portable.Net distribution. The li- doesn’t depend on ex- braries are now available as part of the ternal libraries. A much- 11 string name = args[0]; pnetlib package. Another important discussed feature of 12 Console.WriteLine ("Hello, {0}!", name); component is treecc, an aspect-oriented DotGNU is its imple- programming tool that assists in devel- mentation of the Sys- 13 } opment with the DotGNU C# compiler. tem.Windows.Forms li- 14 } MAY 2009 ISSUE 102 23 Anzeige wird separat angeliefert Anzeige wird separat angeliefert :FM<IJKFIP DotGNU Listing 2: Hello-Advanced.cs 01 using System; 11 { 02 using System.Collections; 12 Console.WriteLine("Hello, 03 {0}!", value); 04 public class HelloWorld 13 } 05 { 14 else 06 public static void Main() 15 { 07 { 16 Console.WriteLine("Sorry, you 08 String value; apparently don't have a name!"); 09 value = Environment. 17 } GetEnvironmentVariable("USER"); 18 } 10 if(value != null) 19 } to a virtual machine to be executed via libraries required to process a Win- Listing 1 greets the user with a name an interpreter. This design makes Dot- Forms-dependent program. Sometimes slipped in as input. But why enter a GNU easily portable and explains the you’ll have to create your own DLL li- name for the user when a name is prob- number of supported platforms. braries. The -shared switch will produce ably already defined on the system? The components you’ll use are the these DLLs instead of a .exe. Using the System.Collections library, you ilrun run-time engine, which executes In addition to C#, the DotGNU com- can, among other things, display the the binaries doled out via the cscc com- piler can also compile to Java Virtual contents of all the environment vari- piler, and cscc some-program.cs, which Machine bytecode with the -mjvm ables. If you modify the hello.cs program produces a file called a.out. This file can switch. Remember to use the .jar file to use the System.Collections library then be executed with: extension instead of .exe or .dll. (Listing 2), you can read the username of the user executing the program with ilrun a.out ;`m\@e value = Environment.Get En vi ron ment- After that brief introduction to the com- Variable("USER"), wherein value is a With the -o switch, you can specify a file piler and common options, I’ll honor String type variable. name when compiling your program the long tradition of coding tutorials by with cscc – for instance: writing a “Hello, World” program in C# >\kJ\k>L@ (Listing 1) and compiling it with cscc -o One of the best bits about DotGNU is an cscc -o some-program.exe 5 hello.exe hello.cs. implementation of the System.Windows. some-program.cs The simple program contains only one Forms library that doesn’t require trans- method: Main(). Command-line argu- lation via other popular toolkits such as To print debugging information, use the ments are passed to this method as an Gtk.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    6 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us