[Gtk-sharp-list] Re: [Mono-devel-list] Mono on Windows HOWTO

Brian Rose lists@brianrose.net
Mon, 25 Oct 2004 16:44:42 -0400


>>
>>   C:\cygwin\home\brose\bmp2disp>mcs -r:gtk-sharp -r:System.Drawing gui.cs
>>   error CS0006: Cannot find assembly `gtk-sharp'
>>   Log:
>>
>>   Compilation failed: 1 error(s), 0 warnings
>>
>> So how do I find the gtk-sharp assembly or see what assemblies are 
>> installed?
>>
> 
> I tried installing the GTK library with the Win32 installer from 
> http://gtk-sharp.sourceforge.net/index.html . I still get the same 
> error. How do I find out which assemblies are installed and where they are?
> 
> I assume that I can use the -lib:PATH to add the library path on the 
> command line, but how do I find out where this installer put the 
> assembly? Is it a .dll a .lib?
> 

Thanks to all who replied. Everything worked fine once I found the GTK 
libraries in the Mono installation. I did not have to install the GTK 
library because it is included by default in the Windows installation. So 
all you need to do is install, compose, compile and run!

(sorry for the word wrap)
mcs -out:gui.exe -r:System.Drawing -r:gtk-sharp -lib:"C:\Program 
Files\Mono-1.0.2\lib\mono\gtk-sharp" gui.cs

And here is the program. I'm putting together a document that explains the 
process in gritty detail as well as advocating the use of other tools like 
make (using Cygwin). Basically a "Setting up an Open Source development 
machine in Windows". I'll post it here when I am done.

// helloworld.cs - Gtk# Tutorial example

using Gtk;
using GtkSharp;
using System;
using System.Drawing;


public class helloworld {

/* This is a callback function. The data arguments are ignored
  * in this example. More on callbacks below. */
static void hello (object obj, EventArgs args)
{
	// Console.WriteLine("Hello World");
	Application.Quit ();
}

static void delete_event (object obj, DeleteEventArgs args)
{
	/* If you return FALSE in the "delete_event" signal handler,
	 * GTK will emit the "destroy" signal. Returning TRUE means
	 * you don't want the window to be destroyed.
	 * This is useful for popping up 'are you sure you want to quit?'
	 * type dialogs. */
     Console.WriteLine ("delete event occurred\n");
     Application.Quit ();
}

public static void Main(string[] args)
{
	/* This is called in all GTK applications. Arguments are parsed
	 * from the command line and are returned to the application. */
	Application.Init ();

	/* create a new window */
	Window window = new Window ("helloworld");
	/* When the window is given the "delete_event" signal (this is
	 * given by the window manager, usually by the "close" option, or
	 * on the titlebar), we ask it to call the delete_event ()
	 * function as defined above. The data passed to the callback
	 * function is NULL and is ignored in the callback function. */

	window.DeleteEvent += new DeleteEventHandler (delete_event);

	/* Sets the border width of the window. */
	window.BorderWidth = 10;
	window.Resize(250, 250);
	
	/*  gtk_container_set_border_width (GTK_CONTAINER (window), 10);*/

	/* Creates a new button with the label "Hello World". */
	Button btn = new Button ("Press to quit");

	/* When the button receives the "clicked" signal, it will call the
	 * function hello() passing it NULL as its argument.  The hello()
	 * function is defined above. */
	btn.Clicked += new EventHandler (hello);


	/* This packs the button into the window (a gtk container). */
	window.Add (btn);

	/* The final step is to display this newly created widget. */
	window.ShowAll ();


	/* All GTK applications must have a gtk_main(). Control ends here
	* and waits for an event to occur (like a key press or
	* mouse event).
	* In C#, we use Application.Run(), as used in Windows.Forms*/

	Application.Run ();

}
}