我已经在 Debian Stable Linux 中安装了 Csharp 和 Gtk(2 和 3),我正在尝试运行文件夹 /usr/share/gtk-sharp2-examples/ 中的 gtk 示例代码文件。这个简单的文件包含:
// HelloWorld.cs - GTK Window class Test implementation
//
// Author: Mike Kestner <mkestner@speakeasy.net>
//
// (c) 2001-2002 Mike Kestner
namespace GtkSamples {
using Gtk;
using Gdk;
using System;
public class HelloWorld {
public static int Main (string[] args)
{
Application.Init ();
Gtk.Window win = new Gtk.Window ("Gtk# Hello World");
win.DeleteEvent += new DeleteEventHandler (Window_Delete);
win.ShowAll ();
Application.Run ();
return 0;
}
static void Window_Delete (object obj, DeleteEventArgs args)
{
Application.Quit ();
args.RetVal = true;
}
}
}
但是,在使用命令 csharp 运行它时,出现以下错误:
$ csharp HelloWorld.cs
(7,8): error CS0246: The type or namespace name `Gtk' could not be found. Are you missing an assembly reference?
(7,8): error CS0246: The type or namespace name `Gtk' could not be found. Are you missing an assembly reference?
(7,8): error CS0246: The type or namespace name `Gtk' could not be found. Are you missing an assembly reference?
(7,8): error CS0246: The type or namespace name `Gtk' could not be found. Are you missing an assembly reference?
... (many times) ...
我安装了以下版本的 Gtk:
Package Installed Previous Now State
=======================-===============-===============-===============-=====
gtk-sharp2 2.12.40-2 2.12.40-2 2.12.40-2 install
gtk-sharp2-examples 2.12.40-2 2.12.40-2 2.12.40-2 install
gtk-sharp2-gapi 2.12.40-2 2.12.40-2 2.12.40-2 install
gtk-sharp3 2.99.3-2+b1 2.99.3-2+b1 2.99.3-2+b1 install
gtk-sharp3-examples 2.99.3-2 2.99.3-2 2.99.3-2 install
gtk-sharp3-gapi 2.99.3-2+b1 2.99.3-2+b1 2.99.3-2+b1 install
顺便说一句,使用 Gtk 的cobra 语言代码文件可以在同一系统上正确运行:
(这个例子来自:http ://cobra-language.com/trac/cobra/wiki/GtkSimpleWindow )
@args -pkg:gtk-sharp-2.0 # version 3.0 also works;
use Gtk
class MyWindow inherits Window
def onDeleteEvent(obj, args as DeleteEventArgs)
"""
This method is tied to the deleteEvent, and is called when the close
button is clicked. It causes the application to quit.
"""
Application.quit
cue init(title as String)
# pass the title to the parent window
base.init(title)
# set a size for our window
.setDefaultSize(300, 200)
# register method to handle the close event
listen .deleteEvent, ref .onDeleteEvent
class MainProgram
def main
# initialise the application
Application.init
# create an instance of our main window
window = MyWindow("Cobra's First Window")
# show all the widgets within the window
window.showAll
# start running the application
Application.run
问题出在哪里,如何解决?谢谢你的帮助。