Setting up the environment

So, Mars is a framework that will let Pharo programmers to build native UIs for Windows, Linux and MacOS. Basically, Mars  will be able to do that by using the user interface frameworks that run on each of those operating systems (Windows Forms, GTK and Cocoa respectively).

Esteban suggested to start with Linux. Bad for me, as it is the OS which I’m the least comfortable with! 😛 But let’s take that as an opportunity to document all the headaches I find while I’m trying to set up the environment, so hopefully it will help the next newbie to have less troubles.

So, I will use VirtualBox on a Mac for running a Linux virtual machine. Just for the record, I could also use VMWare Fusion actually, Guille suggested VirtualBox but I think it’s just a matter of taste. So, I need a Linux image for VirtualBox, and Guille suggested to download an Ubuntu image. Here is a list of several Ubuntu images for Virtual Box. First I downloaded an image of Ubuntu 9, but the Pharo PPA didn’t work so I couldn’t install it. After driving myself crazy for a while I chose to download the Ubuntu Linux 12.10 x86 virtual box, and then I could install Pharo on Ubuntu executing this:

sudo add-apt-repository ppa:pharo/stable
sudo apt-get update
sudo apt-get install pharo-vm-desktop

After getting the Pharo VM working with a Pharo image I started installing Mars. This is the code to be executed in a workspace of Pharo to install Mars:

Gofer it
  url: 'http://www.smalltalkhub.com/mc/estebanlm/Mars/main';
  package: 'ConfigurationOfMars';
  load.

And then:

ConfigurationOfMars loadBleedingEdge: 'All'.
Then, here is the code to initialize Mars on Linux:
"initialize icons"
MarsToolIcons uniqueInstance initializeIcons.
"initialize GTK"
GtkLibrary reset.
GtkLibrary uniqueInstance init.
GtkEventLoop startIfNeeded.

Notice the bold line GtkLibrary uniqueInstance init? Well, I got a primitive failure when executing that line. I expected this to happen, as I haven’t yet installed the Gtk libraries for development. Gtk is already running on my Ubuntu VM, but Mars needs the actual code of Gtk besides the compiled version.

Guille told me he has been using Gtk2 but I should install Gtk3, and for that I used the following command line:

sudo apt-get install libgtk-3-dev.

After completing the installation, I still had the “primitive not found” error. Guille had told me that this could happen, and if it happened I had to change the library path in the class method GtkLibrary class>moduleName.

In order to make Mars work with Gtk3 instead of Gtk2 (the version Guille was using), the method now looks like this:

GtkLibrary class>>moduleName 
    OSPlatform isUnix ifTrue:[^'/usr/lib/i386-linux-gnu/libgtk-3.so.0.600.0'].
    OSPlatform isMacOS ifTrue: [ ^'libgtk-quartz-2.0.0.dylib' ].
    self error: 'Gtk not defined for this platform'

I’m still not sure if I chose the correct library path, but at least with that path the primitive failures are not appearing anymore. Imagine that if I didn’t know how to install gtk3 of course I wouldn’t know either what was the library path 😛

After a few failed trials, what I did was this (maybe it’s useful for the next person trying to install this or something similar):

  • I noticed that the primitive failures after executing GtkLibrary uniqueInstance init were due to Alien looking up for the string “gtk_init” in the library indicated in GtkLibrary class>>moduleName.
  • I looked up for all the files in the Ubuntu VM that contained the text “gtk_init” with this command on the Terminal: grep -rl “gtk_init” /usr/lib 
  • I chose a result that intuitively made sense and put it in the moduleName method as it looks above. As I said before, I’m not 100% sure it’s the right library path :$

So my conclusion here is that for future users to be able to install Mars more comfortably, some automated installation process should be available, and for sure the gtk library path should not be hardcoded (because, for example, if now I commit this code, and Guille updates his Mars version, he will get primitive failures because he’s using Gtk2 and doesn’t have Gtk3 installed).

In the end I could execute an example of a Mars application (a simple System Browser for Pharo and a workspace):

MarsBrowser new openOn: Object.
MarsWorkspace new open.

browser

The browser failed when clicking on a Class. I’m still not sure if it’s a known bug, if it’s failing because I may have used the wrong Gtk library path, or something else.

So, the next steps are:

  • Finding a way of making the Mars installation easier on Linux (for now).
  • Exploring the Browser and Workspace example better, fixing and completing features.

6 thoughts on “Setting up the environment

  1. Pingback: How to build a Mars Application: first examples | Mars on Pharo - GSoC 2013

  2. The Password is “reverse” i found it at the VM list link you described above.

    After loading Mars the moduleName class method was already installed in the image.

    GtkLibrary class>>moduleName
    OSPlatform isUnix ifTrue:[^’/usr/lib/i386-linux-gnu/libgtk-3.so.0.600.0′].
    OSPlatform isMacOS ifTrue: [ ^’libgtk-quartz-2.0.0.dylib’ ].
    self error: ‘Gtk not defined for this platform’

    After following your installation I got another Error after evaluation of
    MarsBrowser new openOn: Object.
    GtkBox subclassResponsibility for message createExternalHandle

    Any hints?

    • Yes! There was a mistake in the Metacello configuration. I’ve just fixed it. Please try again evaluating this:

      Gofer it
      url: ‘http://www.smalltalkhub.com/mc/estebanlm/Mars/main’;
      package: ‘ConfigurationOfMars’;
      load.
      (ConfigurationOfMars project version: ‘0.2’) load.

Leave a comment