为什么Gtk示例以一种语言而不是另一种语言运行

时间:2019-06-07 23:40:00

标签: c# cobra cobra-lang

我已经在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 language代码文件在同一系统上正确运行:

(此示例来自: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

问题出在哪里,如何解决?感谢您的帮助。

0 个答案:

没有答案