Patch for Monodevelop 2.0 debugger for Mono 2.4.2.2

July 26th, 2009

A while ago I posted a how-to on compiling Mono 2.4 from source on Ubuntu. After the release of a minor version update for mono, Mono 2.4.2.2 it was impossible to compile debugger support for Monodevelop 2.0 using Mono 2.4.2.2 sources.

The reason is because in mono 2.4.2.2 the mono-debugger was also updated, to version 2.4.2.1, breaking compatibility with monodevelop-debugger-mdb-2.0. I found a way to solve this and provide a patch.

Download the patch from here.

Applying the patch

Copy the patch from where you downloaded it, to the directory containing the source directory for monodevelop-debugger-mdb-2.0, e.g (~/src/mono-2.4.2.2).

And patch the sources like this:

patch -p0 < monodevelop-debugger-mdb-2.0.mono-debugger-2.4.2.1.patch

The resulting output  output should be something similar to this:

anirothan@lapitop:~/src/mdb-patch/original$ patch -p0 < monodevelop-debugger-mdb-2.0.mono-debugger-2.4.2.1.patch
patching file monodevelop-debugger-mdb-2.0/Mono.Debugging.Server.Mdb/RuntimeInvokeManager.cs
anirothan@lapitop:~/src/mdb-patch/original$

Now you can confiure & make & make install the sources as usual.

Share and enjoy Wink
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • LinkedIn
  • MySpace
  • Reddit
  • Technorati
  • TwitThis

Monodevelop 2.0 debugger with Mono 2.4.2.2

July 26th, 2009

A while ago I posted a how-to on compiling Mono 2.4 from source on Ubuntu. Well, the mono project released an update: mono 2.4.2.2 about a month ago. So, obviously people wanted to update their systems and tried to compile the new source packages. But there seems to be a problem. The debugger plugin for monodevelop 2.0 (monodevelop-debugger-mdb-2.0) failed to compile.

Responding to a series of comments on my blog mentioning this annoying problem I looked into the situation and I have produced a patch for monodevelop-debugger-mbd-2.0 sources. You can download the patch from here, and the instructions on applying it in this post.

As it turns out, in mono 2.4.2.2 there is a new version of the mono debugger, version 2.4.2.1. And with this new version came some breaking changes. Monodevelop uses the mono debugger through a plugin (contained in this source package: monodevelop-debugger-mdb-2.0.tar.bz2). The sources of the plugin were not updated for the new version of mono debugger so any attempt to compile them failed.

Following is an excerpt from the compilation indicating the problem:

./RuntimeInvokeManager.cs(49,50): warning CS0612: `Mono.Debugger.Thread.RuntimeInvoke(Mono.Debugger.Languages.TargetFunctionType, Mono.Debugger.Languages.TargetStructObject, Mono.Debugger.Languages.TargetObject[], bool, bool)' is obsolete
./RuntimeInvokeManager.cs(57,68): error CS1501: No overload for method `AbortInvocation' takes `0' arguments
./RuntimeInvokeManager.cs(78,60): error CS1501: No overload for method `AbortInvocation' takes `0' arguments
Compilation failed: 2 error(s), 2 warnings
make[1]: *** [../build/DebuggerServer.exe] Error 1
make[1]: Leaving directory `/home/anirothan/src/mono-2.4.2.2/monodevelop-debugger-mdb-2.0/Mono.Debugging.Server.Mdb'
make: *** [all-recursive] Error 1

The problem is with the monodevelop-debugger-mdb-2.0/Mono.Debugging.Server.Mdb/RuntimeInvokeManager.cs file. On line 49 the RuntimeInvoke() mehtod is deprecated in the new version of mono debugger as indicated by the warning message, and the two invocations to AbortInvocation() on lines 57 and 78 have incompatible signatures with the method’s definition.

Invocation of AbortInvocation in monodevelop-debugger-mdb-2.0/Mono.Debugging.Server.Mdb/RuntimeInvokeManager.cs lines 55-58 and 76-79:

res.Abort ();
res.CompletedEvent.WaitOne ();
ctx.Thread.AbortInvocation ();
WaitToStop (ctx.Thread);

The AbortInovacation() method is defined in the mono debugger package, in mono-debugger-2.4.2.1/classes/Thread.cs.  If you compare this method between mono-debugger-2.4 and mono-debugger-2.4.2.1 you will see that in 2.4 it is public whereas in 2.4.2.1 it is made internal. Therefore, we couldn’t just figure out what the parameter to AbortInvocation() should be since there would be now way of invoking it.

AbortInvocation() in mono-debugger-2.4

public void AbortInvocation ()
{
  CommandResult result;

  lock (this) {
    check_alive ();
    result = servant.AbortInvocation ();
  }

  result.Wait ();
}

AbortInvocation() in mono-debugger-2.4.2.1

internal void AbortInvocation (long rti_id)
{
  lock (this) {
    check_alive ();
    servant.AbortInvocation (rti_id);
  }
}

However, all is not lost. It seems that in RuntimeInvokeManager.cs there is an obvious code duplication in lines 55-58 and 76-79 where AbortInvocation() is called. It seems that these lines have been moved from the monodevelop debugger plugin to the mono debugger itself. Indeed, below is how Abort() is defined in the RuntimeInvokeResult class in mono-debugger-2.4.2.1/classes/Thread.cs and mono-debugger-2.4/classes/Thread.cs:

in 2.4:

public override void Abort ()
{
  thread.Stop ();
}

and in 2.4.2.1

public override void Abort ()
{
  Thread.AbortInvocation (ID);
  completed_event.WaitOne ();
}

There it goes! The offending call to AbortInvocation(), which caused the compilation to fail, has been moved to Abort(), which is already being called on lines 55 and 76.

So, all we need to do is delete lines 56, 57 and 77,78 from RuntimeInvokeManager.cs. If we try to compile monodevelop-debugger-mdb-2.0 after this simple change we will see no more error messages and the debugger will work in monodevelop 2.0.

RuntimeInvokeManager.cs
Share and enjoy Wink
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • LinkedIn
  • MySpace
  • Reddit
  • Technorati
  • TwitThis

Using Interactive C# (REPL)

June 18th, 2009

The REPL, that is Read Eval Print Loop, is a feature provided by many programming language environments today, such as Python, Ruby, Scala and Haskel. For those who are not familiar with the notion, you could think of REPL as an interactive interpreter (even though it’s not always implemented as one). You can find more info here.

It practically is an interactive prompt (like a UNIX shell, or Windows PowerShell), that accepts expressions in your favorite programming language syntax. There was no practical implementation of a REPL for C# until the Mono project implemented a C# Interactive Shell in Mono 2.2, called csharp. It comes with two flavors: 1). as a command line shell under the name csharp and 2). with a graphical front end called GSharp.

I am sure that every developer, novice or seasoned, needs to test out some small snippet of code, from time to time, to make sure that it does what it is supposed to do. This is also true for C# developers. However, in the absence of a REPL for C#, the only way to do that was by creating a whole new project in Visual Studio or MonoDevelop with a very simple console application. Not only it seems like an overkill if you just want to test a few lines of code, but you also end up with a bunch of little test projects that you are never going to need.

However, now that Mono implemented a C# REPL there is no need to create a test console project for everything. It is extremely useful if you want to test out some piece of code.

An example from my own experience is when, in a C# project I have been working on, I needed to dynamically create a list of enum field values and their string names. I was not 100% percent sure of the way I thought of implementing this, so I wanted to test it out first.

Here it is, in the csharp interactive C# shell, running from a Linux command line:

anirothan@netbook:~$ mono-2.4 csharp
Mono C# Shell, type "help;" for help

Enter statements below.
csharp> var fileModeNames = Enum.GetNames(typeof(System.IO.FileMode));
csharp> fileModeNames;
{ "CreateNew", "Create", "Open", "OpenOrCreate", "Truncate", "Append" }
csharp> var fileModeValues = Enum.GetValues(typeof(System.IO.FileMode));
csharp> fileModeValues;
{ CreateNew, Create, Open, OpenOrCreate, Truncate, Append }
csharp> var pairs = new Dictionary<string, System.IO.FileMode>();
csharp> for(int i=0; i<fileModeValues.Length; ++i)
 > pairs.Add(fileModeNames[i], fileModeValues.GetValue(i));
{interactive}(2,7): error CS1502: The best overloaded method match for `System.Collections.Generic.Dictionary<string,System.IO.FileMode>.Add(string, System.IO.FileMode)' has some invalid arguments
/opt/mono-2.4/lib/mono/2.0/mscorlib.dll (Location of the symbol related to previous error)
{interactive}(2,7): error CS1503: Argument `#2' cannot convert `object' expression to type `System.IO.FileMode'
csharp> var pairsCorrect = new Dictionary<string, object>();     
csharp> for(int i=0; i<fileModeValues.Length; ++i)               
 > pairsCorrect.Add(fileModeNames[i], fileModeValues.GetValue(i));
csharp> pairsCorrect;
{{ "CreateNew", CreateNew }, { "Create", Create }, { "Open", Open }, { "OpenOrCreate", OpenOrCreate }, { "Truncate", Truncate }, { "Append", Append }}
csharp> pairsCorrect["CreateNew"]
 > ;
CreateNew
csharp> quit;
null

That was fairly easy and simple. The intention was to create a dictionary of enum field names and values. For the sake of testing I used the System.IO.FileMode enum.

The flexibility of the csharp REPL does not end there. Here is an extract from a session in gsharp (The gtk+ graphical front-end to csharp) which actually creates a window with a dropdown list.

csharp> LoadPackage("gtk-sharp-2.0");
csharp> using Gtk;
csharp> var window = new Window("Simple dropdown list binding test with csharp REPL");
csharp> var vbox = new VBox();
csharp> var label = new Label("This is a simple test.");
csharp> vbox.PackStart(label);
csharp> var model = new ListStore(typeof(System.IO.FileMode), typeof(string));
csharp> var fileModeNames = Enum.GetNames(typeof(System.IO.FileMode));
csharp> fileModeNames;
{ "CreateNew", "Create", "Open", "OpenOrCreate", "Truncate", "Append" }
csharp> var fileModeValues = Enum.GetValues(typeof(System.IO.FileMode));
csharp> fileModeValues;
{ CreateNew, Create, Open, OpenOrCreate, Truncate, Append }
csharp> var model = new ListStore(typeof(System.IO.FileMode), typeof(string));
csharp> for(int i=0; i<fileModeValues.Length; ++i)
 > model.AppendValues(fileModeValues.GetValue(i), fileModeValues[i]);
{interactive}(2,48): error CS0021: Cannot apply indexing with [] to an expression of type `System.Array'
csharp> for(int i=0; i<fileModeValues.Length; ++i)
model.AppendValues(fileModeValues.GetValue(i), fileModeNames[i]);
csharp> var dropDown = new ComboBox();
csharp> var renderer = new CellRendererText();
csharp> dropDown.PackStart(renderer, true);
csharp> dropDown.AddAttribute(renderer, "text", 1);
csharp> dropDown.Model = model;
{ { CreateNew, "CreateNew" }, { Create, "Create" }, { Open, "Open" }, { OpenOrCreate, "OpenOrCreate" }, { Truncate, "Truncate" }, { Append, "Append" } }
csharp> vbox.PackEnd(dropDown);
csharp> window.Add(vbox);
csharp> window.ShowAll();
csharp>
The GSharp C# Interactive Shell in action.

The GSharp C# Interactive Shell in action.

There are some limitations though. For example, you cannot create classes (but you can put .cs files in the ~/.config/csharp directory that will be loaded automatically to the interactive shell) and there is an apparent lack of code completion features. However, these limitations are already being worked on and I hope they will become available with mono 2.6.

Share and enjoy Wink
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • LinkedIn
  • MySpace
  • Reddit
  • Technorati
  • TwitThis

Creative ZEN X-Fi on Ubuntu 9.04 Jaunty Jackpole

June 5th, 2009

I have a Creative Zen X-Fi portable media player for some time now. I have managed to make it work with previous Ubuntu versions, but only after a lot of hard work of googling and meddling with the sytem.

I didn’t have the oportunity to test it with the latest Ubuntu since I upgraded everything to 9.04 up until a few days ago.

As with previous Ubuntu versions, 8.10 and 8.04, the Zen was not automatically recognized by any media player, or by Gnomad, which by the way is sooooo awful.

After doing some digging around in the ubuntuforums I found a way to make it happen.

The problem is that the version of libmpt (the library that makes things work) provided by the canonical repositories is an older one and does not support the player out of the box.

Running mtp-detect from the command line, connected to the player but seemed not to recognize it.

In the forums there was a reference for a PPA repository that contained more recent versions. I tried adding the repository to apt but could not get the libmtp package to upgrade (don’t know why). So, I simply downloaded the deb packages manually, libmtp8_0.3.5-0ubuntu1_i386.deb, mtp-tools_0.3.5-0ubuntu1_i386.deb, from here. Then I installed them manually with GDebi.

That did it. Running mtp-detect now, connected and recognized the player. So did Amarok, Banshee and Rhythmbox.

So, if you want to get your Createive ZEN X-Fi working under Jaunty then you simply have to manually install the 2 packages I mentioned above.

Share and enjoy Wink
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • LinkedIn
  • MySpace
  • Reddit
  • Technorati
  • TwitThis

Adobe AIR on Ubuntu and software installation on Linux

April 7th, 2009

I was looking for a twitter application that could be integrated to my desktop environment. Not something web based, or browser based like TwitterFox. twitter.com has a list of desktop applications. Most of these are Adobe Air based. I have set my eye on installing Twhirl. I needed AIR for that.

Adobe Air (Adobe Integrated Runtime) is a cross-platform runtime environment for rich internet applications that can be deployed on the desktop. It is based on Webkit and Flash technologies.

Ubuntu does not come with Adobe Air pre-installed so I looked it up in Synaptic to see if it is available on one of the repositories. Unfortunately it was not. I don’t like it when something does not have ready deb packages because most of the time that means that you will have to either compile the application from source code yourself or install the binaries by simply copying them to some folder. Unless you do that for development or testing purposes it just not worth it.

Adobe AIR installer in action.

Adobe AIR installer in action.

This big difference with the “Windows philosophy” of installing software is often a major point of criticism of Linux. It is true that proprietary software is not that easy to install on Linux as in Windows. But, it is not Linux that should be put to blame. It is those who release ports of their applications to Linux without offering debian or rpm packages, or a proper installation wizard.

Adobe AIR for Linux is an exception that proves that if the vendor is willing, it can provide an easy way to install and integrate to your system.

The Setup screen.

The Setup screen.

I downloaded the installer, named AdobeAIRInstaller.bin. I expected an awful command line installer that would resolve to unnecessary dialogs and file copying. None of  that! I got the same process and same look and feel as the windows installer. A truly cross platform procedure. To my surprise, the installer integrated Adobe AIR to the packaging system with a proper debian package. It also integrated excellently into Gnome creating proper menu entries. The only minus point is that I still had to execute the installer from the command line

Installing Twhirl

Installing Twhirl

When I downloaded Twhirl, I did not expect that it would install itself just by double clicking the twhirl-0.8.6.air file. But it did! I didn’t expect it to update itself so easily neither. It looked and felt exactly the same as when I tried it later on a windows box.

AIR and Twhirl menu entries after setup.

AIR and Twhirl menu entries after setup.

Also, the runtime integrated a debian package to dpkg. Output from apt-cache:

anirothan@monarch:~$ apt-cache --installed --names-only search adobeair
adobeair1.0 - Adobe AIR
anirothan@monarch:~$ apt-cache --installed --names-only search twhirl
de.makesoft.twhirl.0ea062bc275e7ed1e6ec3762effd73c7158adf33.1 - twhirl - a social networking client 

I’m not trying to promote Adobe or anything. Other Adobe products like Adobe Reader do not offer this kind of experience. It just proves my point. Installation of proprietary software can be as easy as in Windows. With all that wizards and stuff. The only thing that is required is the vendor’s commitment in cross-platform development. 

Personally, I think that package repositories, either deb or rpm, are far superior to the installation paradigm promoted in Windows. What can beat a simple apt-get install <software name here>, or a full blown graphical package manager?

Share and enjoy Wink
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • LinkedIn
  • MySpace
  • Reddit
  • Technorati
  • TwitThis

Building Mono 2.4 from source on Ubuntu 8.10

April 1st, 2009

Sad to say that the latest versions of Ubuntu and Debian do not provide the latest packages of Mono preferring stability over bleeding edge. Also, according to the packagers’  mailing list it is not an easy task to provide packages for mono and all the software that binds to it.

I am a sucker for bleeding edge, especially when it comes to thinks like Mono. The latest stable release of Mono, version 2.4 has a lot of new features like the C# interactive repl shell, SIMD extensions and better support for C# 3/.NET 3.5 features, like extension methods and LINQ. See the release notes here. I was disappointed when the most recent version of mono debian packages I could find were for the 2.0.1 version on third-party repositories.

What to do then? Download the source, configure and build to run in parallel to the version of mono installed in my Ubuntu desktop (the mono run-time is always installed on Ubuntu by default, even the live CD runs it, since it is needed to run .NET applications, like F-Spot, that have become a standard in the GNOME desktop). It turns out that it’s not that difficult as it sounds.

Step 1: Install prerequisites for compilation.

First of all, you will need to setup the appropriate tools for configuring and compiling source code. You can install these through the Synaptic package manager but for the sake of speed let’s use some command line magik Wink

Open a console and type in the following to install the gcc compiler, and development header files needed to compile the mono compilers, tools and library stack.

user@system$> sudo apt-get update
user@system$> sudo apt-get install build-essential autoconf automake \
bison flex gtk-sharp2-gapi boo gdb valac libfontconfig1-dev \
libcairo2-dev libpango1.0-dev libfreetype6-dev libexif-dev \
libjpeg62-dev libtiff4-dev libgif-dev zlib1g-dev libatk1.0-dev \
libglib2.0-dev libgtk2.0-dev libglade2-dev libart-2.0-dev \
libgnomevfs2-dev libgnome-desktop-dev libgnome2-dev libgnomecanvas2-dev \
libgnomeui-dev libgnomeprint2.2-dev libgnomeprintui2.2-dev \
libpanel-applet2-dev libnautilus-burn-dev librsvg2-dev \
libgtkhtml3.14-dev libgtksourceview2.0-dev libgtksourceview-dev \
libvte-dev libwnck-dev libnspr4-dev libnss3-dev libxul-dev \
libwebkit-dev libvala-dev

This should install all the necessary software and development headers needed for the compilation.

Step 2: Download mono 2.4 source archives.

Go to http://ftp.novell.com/pub/mono/sources-stable/ . You don’t need every archive in that list.
In this guide we will use: mono-2.4.tar.bz2libgdiplus-2.4.tar.bz2gluezilla-2.4.tar.bz2xsp-2.4.tar.bz2mono-tools-2.4.tar.bz2gecko-sharp-2.0-0.13.tar.bz2mono-debugger-2.4.tar.bz2mono-addins-0.4.zipgtk-sharp-2.12.8.tar.bz2gnome-sharp-2.20.1.tar.bz2gnome-desktop-sharp-2.20.1.tar.bz2webkit-sharp-0.2.tar.bz2

Also go to the MonoDevelop website and download the sources for monodevelop 2.0: monodevelop-2.0, monodevelop-debugger-mdb-2.0, monodevelop-debugger-gdb-2.0, monodevelop-database-2.0, monodevelop-java-2.0, monodevelop-vala-2.0

Create a directory in your home directory for the extracted sources, e.g. src/mono-2.4.

user@system$> mkdir -p src/mono-2.4; cd src/mono-2.4

Extract the downloaded archives to that directory.

Step 3: Prepare the parallel environment

Now it’s time to prepare our system for two versions of the mono runtime. A good idea is to install everything related to mono 2.2 to some path like /opt/mono-2.2 and create shell script to load an environment that will use the version located in that path instead of the default installation. That way you will not render your existing mono installation unstable or broken.

Now create a script that will load the separate mono-2.4 environment.

user@system$> cat > mono-2.4-environment
#!/bin/bash
MONO_PREFIX=/opt/mono-2.4
GNOME_PREFIX=/opt/gnome-2.4
export DYLD_LIBRARY_PATH=$MONO_PREFIX/lib:$DYLD_LIBRARY_PATH
export LD_LIBRARY_PATH=$MONO_PREFIX/lib:$LD_LIBRARY_PATH
export C_INCLUDE_PATH=$MONO_PREFIX/include:$GNOME_PREFIX/include
export ACLOCAL_PATH=$MONO_PREFIX/share/aclocal
export PKG_CONFIG_PATH=$MONO_PREFIX/lib/pkgconfig:$GNOME_PREFIX/lib/pkgconfig
PATH=$MONO_PREFIX/bin:$PATH
PS1="[mono-2.4] \w @ "

[Press Ctrl+D for EOF to write the file and get back to the prompt]

user@system$> sudo mv mono-2.4-environment /usr/local/bin
user@system$> sudo chmod +x /usr/local/bin/mono-2.4-environment

And create a second script that will load the environment and execute its argurments.

user@system$> cat > mono-2.4
#!/bin/bash
MONO_PREFIX=/opt/mono-2.4
GNOME_PREFIX=/opt/gnome-2.4
export DYLD_LIBRARY_PATH=$MONO_PREFIX/lib:$DYLD_LIBRARY_PATH
export LD_LIBRARY_PATH=$MONO_PREFIX/lib:$LD_LIBRARY_PATH
export C_INCLUDE_PATH=$MONO_PREFIX/include:$GNOME_PREFIX/include
export ACLOCAL_PATH=$MONO_PREFIX/share/aclocal
export PKG_CONFIG_PATH=$MONO_PREFIX/lib/pkgconfig:$GNOME_PREFIX/lib/pkgconfig
PATH=$MONO_PREFIX/bin:$PATH

exec "$@"

[Press Ctrl+D for EOF to write the file and get back to the prompt]

user@system$> sudo mv mono-2.4 /usr/local/bin
user@system$> sudo chmod +x /usr/local/bin/mono-2.4

Load the environment:

user@system$> source mono-2.4-environment

After this command, the prompt should change and contain [mono-2.4] to indicate that you are operating in a Mono 2.4 environment.

[mono-2.4] ~ @ cd ~/src/mono-2.4

NOTE! For the sake of readability the prompt indication in the instructions will remain the generic user@system$> but for the rest of the guide you must make sure that you follow each step while in the 2.4 environment.

And now create the directory where everything will be installed:

user@system$> sudo mkdir -p /opt/mono-2.4

Step 4: libgdiplus

Before compiling the main sources of mono we must compile libgdiplus if we want to have an implementation of the System.Drawing namespace.

user@system$> cd libgdiplus-2.4
user@system$> ./configure --prefix=/opt/mono-2.4 --with-pango

The output of the configure script should be something like this:

---
Configuration summary

   * Installation prefix = /opt/mono-2.4
   * Cairo = 1.8.0 (system)
   * Text = pango
   * EXIF tags = yes
   * Codecs supported:

      - TIFF: yes
      - JPEG: yes
      - GIF: yes
      - PNG: yes
      NOTE: if any of the above say 'no' you may install the
            corresponding development packages for them, rerun
            autogen.sh to include them in the build.

---

If any of the options say no then you have a missing dependency. You might want to use the Synaptic package manager to find the appropriate package to install. However, these dependencies are optional.

Now it’s time to build the source.

user@system$> make
user@system$> sudo make install

Step 5: mono-2.4

Now it’s time to compile mono’s main sources which will produce, among others, the c# compilers and the base class libraries.

user@system$> cd ../mono-2.4
user@system$> ./configure --prefix=/opt/mono-2.4
user@system$> make
user@system$> sudo make install

Verify that the mono compilers have been installed:

user@system$> which gmcs

This should output: /opt/mono-2.4/bin/gmcs
Your existing mono installation will be preserved since everything is installed to the /opt/mono-2.4 directory.

Step 6: gtk+ and gnome

Now it’s turn to compile libraries needed for desktop environment, namely gtk-sharp, gnome-sharp, gnome-desktop-sharp, gtksourceview-sharp.

user@system$> cd ../gtk-sharp-2.12.8
user@system$> ./configure --prefix=/opt/mono-2.4
user@system$> make
user@system$> sudo make install
user@system$> cd ../gnome-sharp-2.20.1
user@system$> ./configure --prefix=/opt/mono-2.4
user@system$> make
user@system$> sudo make install
user@system$> cd ../gnome-desktop-sharp-2.20.1
user@system$> ./configure --prefix=/opt/mono-2.4
user@system$> make
user@system$> sudo make install

Step 7: gluezilla, gecko-sharp, webkit-sharp

Now lets compile libraries for embedding the gecko and webkit html rendering engines.

user@system$> cd ../gluezilla-2.4
user@system$> ./configure --prefix=/opt/mono-2.4
user@system$> make
user@system$> sudo make install
user@system$> cd ../gecko-sharp-2.0-0.13
user@system$> ./configure --prefix=/opt/mono-2.4
user@system$> make
user@system$> sudo make install
user@system$> cd ../webkit-sharp-0.2
user@system$> ./configure --prefix=/opt/mono-2.4
user@system$> make
user@system$> sudo make install

Step 8: build Mono.Addins

Turn to compile the Mono.Addins libraries:

user@system$> cd ../mono-addins-0.4
user@system$> ./configure --prefix=/opt/mono-2.4
user@system$> make
user@system$> sudo make install

Step 9: build Mono tools

Now it’s turn to compile the marvelous collection of Mono tools, including Gendarme and GSharp (the C# interactive shell).

user@system$> cd ../mono-tools-2.4
user@system$> ./configure --prefix=/opt/mono-2.4
user@system$> make
user@system$> sudo make install

After this you have installed the gsharp tool. Test it out:

user@system$> gsharp

Play a little with the C# repl Smile Type quit; when you’re done.

Step 10: build Mono XSP

This is actually something very useful. XSP is a standalone web server developed in C#. It can be run through the command line or even embedded into your application by referencing the Mono.WebServer assembly.

user@system$> cd ../xsp-2.4
user@system$> ./configure --prefix=/opt/mono-2.4
user@system$> make
user@system$> sudo make install

Step 11: build the Mono Debugger

Getting closer to the end of our compilation session, let’s build the mono debugger allowing us to debug the faulty software we write.

user@system$> cd ../mono-debugger-2.4
user@system$> ./configure --prefix=/opt/mono-2.4
user@system$> make
user@system$> sudo make install

Step 12: build MonoDevelop 2.0

Now what would all this be without a nice IDE? MonoDevelop 2.0 brings us finally debugger support!

user@system$> cd ../monodevelop-2.0
user@system$> ./configure --prefix=/opt/mono-2.4
user@system$> make
user@system$> sudo make install
user@system$> cd ../monodevelop-debugger-mdb-2.0
user@system$> ./configure --prefix=/opt/mono-2.4
user@system$> make
user@system$> sudo make install
user@system$> cd ../monodevelop-debugger-gdb-2.0
user@system$> ./configure --prefix=/opt/mono-2.4
user@system$> make
user@system$> sudo make install
user@system$> cd ../monodevelop-database-2.0
user@system$> ./configure --prefix=/opt/mono-2.4
user@system$> make
user@system$> sudo make install
user@system$> cd ../monodevelop-java-2.0
user@system$> ./configure --prefix=/opt/mono-2.4
user@system$> make
user@system$> sudo make install
user@system$> cd ../monodevelop-vala-2.0
user@system$> ./configure --prefix=/opt/mono-2.4
user@system$> make
user@system$> sudo make install

And… That’s it. You now have a working mono-2.4 environment and an excellent IDE to work with.

You can launch any .NET program with Mono 2.4 with:

user@system$> mono-2.4 PATH_TO_THE_PROGRAM_AND_ITS_ARGUMENTS_IF_ANY

For example to launch MonoDevelop 2.0:

user@system#> mono-2.4 monodevelop

NOTE! This will work only for shell scripts that are normally distributed with mono applications. If you look at /opt/mono-2.4/bin/monodevelop you will see that it is a shell script that essentially runs something like this: mono /opt/mono-2.4/lib/monodevelop/bin/MonoDevelop.exe. Trying to execute a .NET application, e.g. called main.exe, by typing mono-2.4 main.exe will fail. You sould type mono-2.4 mono main.exe instead.

Enjoy hacking!

Share and enjoy Wink
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • LinkedIn
  • MySpace
  • Reddit
  • Technorati
  • TwitThis

The one about my “Joy Machine!”

March 24th, 2009

What I always wanted was a “joy machine”. That is, a system that would always be on, would act as a server and give me room for experiments. Of course, that system would be based on Linux. It just gives a lot more room for customization, hacking and experimentation.

The first thing that I thought of doing was to make a second desktop PC and just leave it always on. But, I needed this to be a “quiet” system. Event the humming of the cooling fans can become very frustrating when you are trying to sleep and even though I don’t really mind the noise, it is a cause of headaches over time. I had an old Pentium 2, 333 MHz processor and motherboard, a spare IDE hard-disk and 256 MB of RAM, so I decided to create a headless (that is without a monitor and keyboard) system based on that hardware. My initial plan was to set it up in some special protective casing on the balcony of my apartment, but I ended up using an empty firehouse casing and installing the system next to the apartment entrance at the stairs.

Rigging the case to house an old motherboard, two hard disks (one at first) and a power supply unit was trivial but very fun!

Inside this box is living a Debian system. Initially I installed Debian etch but I recently upgraded to lenny. Usage and administration is performed remotely through ssh. Apart from being a Linux enthusiast’s playground, the machine also serves as DNS server for my local LAN, NFS and Samba to serve files, MySQL/Apache/Python/Ruby/PHP for web development.  Also,  it contains several subversion repositories for my pet projects. The home directory is mounted on a LVM partition. That makes it a whole lot easier to expand the filesystem size in the future. It is also very useful for doing large downloads, e.g through bittorrent (using rtorrent) or rapidshare (shell script around,  wget) with the help of the screen utility.

Even though the system is low spec it performs superbly. The memory usage is always topped and the swap is rarely touched. It even manages to stream 1080p video with ease. One time, after an experiment with LVM went wrong, I had to boot the system with an Ubuntu Live CD to do some restore work. I hooked the machine with a spare display, a keyboard, a mouse and a really old x2 CD-ROM drive. Booting to the live CD using a x2 drive and with a 333 MHz processor took a few minutes but the astonishing thing was that even though the system has only 256 MB of RAM, it actually managed to load Gnome and also open various applications like Firefox! Too bad I didn’t make a screenshot of it.

All in all, playing with the system is most fun, it really is a “Joy-Machine”!. It is also a perfect example of how old, low-spec hardware can be put to use with Linux (one could of course use some other open source OS like FreeBSD or OpenBSD). You wouldn’t be able to setup a system like this with a Microsoft Windows Server. Compared to M$ Windows, Linux is usable on a broader spectrum of hardware.

Share and enjoy Wink
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • LinkedIn
  • MySpace
  • Reddit
  • Technorati
  • TwitThis

Raising Elephants Is So Utterly Boring!!!

March 20th, 2009

What do elephants have to with me? Ehmmm, nothing! This post is not about elephants, of course, but about a not so well known feature of the Linux kernel which has to do with safe system termination or reboot.

Raising Elelephants Is So Utterly Boring

Raising Elelephants Is So Utterly Boring

Suppose you do something silly, like load an unstable kernel driver, or you use unstable versions of some applications or simply you stumble upon a weird bug, and suddenly your system appears to have hanged. Hmmm… what to do? If you were in a Windows environment, you would probably hit the notorious Ctrl+Alt+Delete key combo to get the task manager appear on screen. Then, you would either kill the process that’s causing all the fuss or you would hit reboot or shutdown to safely switch your system off without risking data corruption. I’m sure that everyone who uses windows has been in a situation where simply hitting Ctrl+Alt+Delete did not work, the task manager was nowhere and they were forced to hit the “evil” reset button in dreadful fear and guilt of doing something that could render precious data corrupted.

Unfortunately,  you cannot do anything else in that sort of situation. That is, if you are a windows user…

Linux users can feel a lot safer than their friends, the windows users, for their daily chores, because there is more to Linux than hitting a Ctrl+Alt+Del combo each time something becomes unresponsive. Healing a system that appears to be hanged is a series of actions, each action to be taken if the previous fails. Now, here’s what to do in such a case:

  1. If you are in a desktop session, running GNOME, KDE or any other window manager, press Ctrl+Alt+F1 or F2 or F3… or F6. In Linux user sessions run in virtual terminals. Virtual terminals 7 and above are reserved for graphical sessions running on X, and terminals 1 to 6 are for console sessions. A user can switch any time between any virtual terminal by hitting the Ctrl+Alt+F# key combo, where # is the number of the virtual terminal. So, hitting Ctrl+Alt+F1 for example will switch to console mode and a login prompt will appear. Login, and use the standard shell tools, like top and ps to determine what process is causing the problem and kill it with the kill utility. Then logout and press Ctrl+Alt+F7 to get back to you desktop session.
  2. If the system refuses to switch to another VT (virtual terminal) try to kill the X session by hitting the Ctrl+Alt+Backspace key combination. This will effectively kill every graphical application and restart the X Server. In the end you should be brought back to the login screen.
  3. If step 2 fails, then try pressing Ctrl+Alt+Delete. The system will beep and initiate the reboot sequence.
  4. If you don’t hear a beep, or if you do hear it but the computer is not rebooting after some time, hit the Ctrl+Alt+Delete combo once more. CAUTION! This will do an unsafe reboot. If the system has not unmounted the filesystems in use skip to the next step.
  5. Something went extremely, horribly wrong. 99% of the time step 1 should suffice. However, even if all of the above fail to give a result, don’t worry. DO NOT in any case hit the reset or power off button. The kernel has a small communications channel open at all times. Even if everything goes wrong you will be able to use this channel to send commands to the kernel.  These commands are sent by holding Ctrl+Atl+PrintScrn/SysRq and pressing a letter designating the command. What you need to do is to remember that Raising Elephents Is So Utterly Boring. The first letters of each word is the sequence of commands you must issue to trigger a safe reboot.  In other words, if everything else fails hold down Ctrl+Alt+PrintScrn/SysRq and press R E I S U B by waiting a few seconds between each key-press to allow the kernel to finish executing each command. R E I S U B is easily remembered through the mnemonic; Raising Elephants Is So Utterly Boring. Or, you can think BUSIER spelled backwards. I prefer the elephants though Smile.

The sequence of the commands executed are:

Ctrl+Atl+PrintScrn/SysRq + R: Get control of the keyboard device.
Ctrl+Atl+PrintScrn/SysRq + E: Send the SIGTERM signal to all processes except init (PID 1).
Ctrl+Atl+PrintScrn/SysRq + I: Send the SIGKILL signal to all processes except init.
Ctrl+Atl+PrintScrn/SysRq + S: Sync all mounted filesystems. This will flush any unwritten data to your devices and thus prevent data loss or corruption.
Ctrl+Atl+PrintScrn/SysRq + U: Remount all mounted filesystems in read-only mode.
Ctrl+Atl+PrintScrn/SysRq + B: Immediate system reboot.  The previous commands must be executed before this one to do a safe reboot.

There are also other commands you may send, but these are the ones needed to reboot in a system hang.

More info on these magic commands can be found here.

So, if you ever get into a tough spot when using your tux machine you won’t have to worry, remember the elephants Grin.

Share and enjoy Wink
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • LinkedIn
  • MySpace
  • Reddit
  • Technorati
  • TwitThis

The one about Centriment

March 14th, 2009

You may be wondering, what is centriment?

Well, it’s a name that just popped into my head one day while playing with some code. If someone asked me to tell him what this invented word means, I’d have to say that it is the feeling that a programmer, a hacker, gets when he is on roll and knows that the hack he is doing right now is super-cool. It is the eureka moment you get when you suddenly realized the solution to a bind-boggling problem. It is the feeling you get when you hunt down and squash to mere pulp the most annoying bug you were ever faced with after a couple of days of exhausting debugging. In other, simpler, words it’s the joy of  hacking.

When I finally decided to setup my own blog, it was clear to me how it should be named. Hence, centriment.com. In this blog I will try and share my experiences and opinions in the field of computing.

If you are also wondering about the subtitle, “stories of the spirit living inside the computer”, it is a tribute to the wizard book (Stucture and Interpretation of Computer Programs) and its authors, Harold Abelson and Gerald Jay Sussman, one the best computer books I ever read (still reading it actually Razz).

Share and enjoy Wink
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • LinkedIn
  • MySpace
  • Reddit
  • Technorati
  • TwitThis

The one about “Hello World”

March 12th, 2009

Hello World!!

This is my first blog post! I am very excited about starting my own blog. I have been a software engineer for many years now and I have always thought about sharing my experiences in the field of computing with others, through a place of my own, but I never seemed to have the time to get down with it. Finally, I’ve setup my own domain, installed wordpress, installed a theme and while writing this I am still experimenting a bit with it.

Since the first thing we do when learning a new programming language is to write a “hello world” program, and this is the first post in this blog, this is about… “Hello Word”!

And here it is in C, the first “real” programming language I’ve learned:

#include <stdlib.h>
#include <stdio.h>

int main(int argc, char *argv[])
{
  printf("Hello Word!");
  return EXIT_SUCCESS;
}

Here it is in C#:

using System;
public class Application
{
  public static void Main(string[] args)
  {
    Console.WriteLine("Hello World!");
  }
}

And here it is in Python:

print "Hello World!"

Every time you start to learn a new language or system you begin by making a simple “hello world” application. It is not useful, it does not do anything, it’s plain stupid code. However, it’s all the most exciting because that’s when you start learning something new and unknown to you. Even such simple code has a lot of knowledge to convey to its author. First of all, you learn if the code has to be compiled and interpreted, if it is compiled to machine code or some other intermediate language executed by a virtual machine. You are also exposed to the basic rules and coding styles. You learn if a language is object oriented, loosely or strictly typed.

Soon after that, you start writing a little less trivial things and start feeling like a kid with a new toy. As you learn even more, you start feeling like a little god that can meddle with his own privately created universe.

And now this is my “hello world” in the blog world!

Remember your “hello world!”s?

Share and enjoy Wink
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • LinkedIn
  • MySpace
  • Reddit
  • Technorati
  • TwitThis