GTK+ und MinGW



  • Hallo, liebe C/C++-Gemeinde,

    ich möchte ein kleines C-Programm mit GUI schreiben. Es soll ein Fenster mit 3 Buttons und einer Grafik (Ani-GIF) werden. Wenn man auf die Buttons drückt soll sich die Grafik ändern. Kompiliert soll es dann als EXE auf jedem Windows-PC laufen können (ohne Zusatzinstallationen).

    Den Compiler habe ich schon installiert: MinGW (GCC) + MSYS. Als GUI habe ich mich für GTK+ entschieden, da in C-Code und (hoffentlich) leicht zu Programmieren. Auf IDE möchte ich verzichten. Nehme nur den Notepad.

    Frage: Wie installiere ich GTK+ am leichtesten unter MinGW (Windows) sodass ich dann ein kl. GTK+-HelloWorld-Programm kopilieren kann (für's erste)?

    Für weitere Tipps wäre ich auch dankbar.

    Grüße,
    goofie 🤡



  • Entweder runterladen und entpacken: http://www.gimp.org/~tml/gimp/win32/

    Oder Installer nutzten: http://gladewin32.sourceforge.net.



  • Hi ProgChild,

    vielen Dank für den Tipp mit Glade. Habe es jetzt installiert und versucht das HelloWorld von GTK+ zu kompilieren. Bekomme leider nur Fehlermeldungen:

    Package gtk+-1.0 was not found in pkg-config search path.
    Perhaps you should add the directory containing gtk+-1.0.pc' to the PKG\_CONFIG\_PATH environment variable No package 'gtk+-1.0' found Package libpng12 was not found in the pkg-config search path. Perhaps you should add the directory containinglinpng12.pc' to the PKG_CONFIG_PATH environment variable
    Package 'libpng12', required by 'cairo', not found
    helloworld.c:1:21: gtk/gtk.h: No such file or directory
    .
    .
    . usw...

    Was muss ich da noch machen?

    Quelltext von helloworld.c :

    #include <gtk/gtk.h>
    
    /* This is a callback function. The data arguments are ignored
     * in this example. More on callbacks below. */
    static void hello( GtkWidget *widget,
                       gpointer   data )
    {
        g_print ("Hello World\n");
    }
    
    static gboolean delete_event( GtkWidget *widget,
                                  GdkEvent  *event,
                                  gpointer   data )
    {
        /* 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. */
    
        g_print ("delete event occurred\n");
    
        /* Change TRUE to FALSE and the main window will be destroyed with
         * a "delete_event". */
    
        return TRUE;
    }
    
    /* Another callback */
    static void destroy( GtkWidget *widget,
                         gpointer   data )
    {
        gtk_main_quit ();
    }
    
    int main( int   argc,
              char *argv[] )
    {
        /* GtkWidget is the storage type for widgets */
        GtkWidget *window;
        GtkWidget *button;
    
        /* This is called in all GTK applications. Arguments are parsed
         * from the command line and are returned to the application. */
        gtk_init (&argc, &argv);
    
        /* create a new window */
        window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    
        /* 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. */
        g_signal_connect (G_OBJECT (window), "delete_event",
    		      G_CALLBACK (delete_event), NULL);
    
        /* Here we connect the "destroy" event to a signal handler.  
         * This event occurs when we call gtk_widget_destroy() on the window,
         * or if we return FALSE in the "delete_event" callback. */
        g_signal_connect (G_OBJECT (window), "destroy",
    		      G_CALLBACK (destroy), NULL);
    
        /* Sets the border width of the window. */
        gtk_container_set_border_width (GTK_CONTAINER (window), 10);
    
        /* Creates a new button with the label "Hello World". */
        button = gtk_button_new_with_label ("Hello World");
    
        /* 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. */
        g_signal_connect (G_OBJECT (button), "clicked",
    		      G_CALLBACK (hello), NULL);
    
        /* This will cause the window to be destroyed by calling
         * gtk_widget_destroy(window) when "clicked".  Again, the destroy
         * signal could come from here, or the window manager. */
        g_signal_connect_swapped (G_OBJECT (button), "clicked",
    			      G_CALLBACK (gtk_widget_destroy),
                                  G_OBJECT (window));
    
        /* This packs the button into the window (a gtk container). */
        gtk_container_add (GTK_CONTAINER (window), button);
    
        /* The final step is to display this newly created widget. */
        gtk_widget_show (button);
    
        /* and the window */
        gtk_widget_show (window);
    
        /* 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). */
        gtk_main ();
    
        return 0;
    }
    

    Kompiliert mit:
    gcc -Wall -g helloworld.c -o helloworld `pkg-config --cflags gtk+-2.0` \
    `pkg-config --libs gtk+-2.0`

    (siehe www.gtk.org/tutorial/)

    Grüße,
    rolly



  • Wie wäre es, wenn du mal nicht mit Version 1.x von GTK+ versuchst, dein Programm zu kompilieren, wenn du die Version 2.x von GTK+ installierst.



  • Hallo,

    wenn ich, wie schon gesagt
    gcc -Wall -g helloworld.c -o helloworld `pkg-config --cflags gtk+-2.0` \
    `pkg-config --libs gtk+-2.0`
    eingebe, versuche ich dann mit Version 1.x von GTK+ zu kompilieren?
    Oder muss ich da noch etwas im Quelltext zu ändern?
    Hmm, ich verstehe das nicht.

    Grüße,
    rolly



  • rolly schrieb:

    Hallo,

    wenn ich, wie schon gesagt
    gcc -Wall -g helloworld.c -o helloworld `pkg-config --cflags gtk+-2.0` \
    `pkg-config --libs gtk+-2.0`
    eingebe, versuche ich dann mit Version 1.x von GTK+ zu kompilieren?
    Oder muss ich da noch etwas im Quelltext zu ändern?

    Nein tust du nicht, aber da oben fehlt ihm die Datei gtk+-1.0.pc. Die würde er aber nur suchen, wenn du pkg-config --libs gtk+-1.0 ausführen würdest. Es macht also keinen sinn, dass er diese Datei vermisst, es sei denn, du hast dich vielleicht vertippt, oder das aus einen GTK+ 1.0 Tutorial rauskopiert.

    Dein Quellcode ist aber schonmal GTK+ 2.x



  • http://www.parinyasoft.com/download.html
    mit paket 4,5,6 haste alles was du brauchst. hast dann halt ne simple ide, kansnt deinen code ja dann reinkopieren oder du büernimsmt du linker optionen einfahc auf die commandline.



  • ok, vielen Dank für die Antworten. Werde mal einiges ausprobieren.
    Noch ne Frage:
    "GTK+ 2.6.4 Runtime DLLs. (You need this package to run your GTK+ Applications)"

    bedeutet das, ich brauche diese "dlls" um zB auf einem anderen PC die EXE starten zu können? Geht das nicht mit standalone-EXE?

    Grüße,
    rolly



  • nein, geht nicht ohne. natürlich könntest du die dateien mit deinen in ein seup basteln (sofern von der lizenz unter der gtk steht erlaubt) oder du lässt beides installieren, gibt ja viele setups wo dann noch n aderes ausgeführt wird.



  • Wenn du GTK+ statisch Linken würdest, müsstest du außerdem deinen Quellcode veröffentlichen, bzw. so wie es in der LGPL ausgedrück ist, dafür sorgen, dass jeder, der dein Programm benutzt, in der Lage ist, die GTK+ Version auszutauschen.



  • hmm was heißt statisch verlinkt? unterschied zwischen statisch verlinkt und dynamisch verlinkt? das mit der veröffentlichung von quellcode usw. ist kein problem.

    ich hätte gerne aber eine EXE ohne dll und installation, ist das möglich?

    grüße,
    rolly



  • Soweit ich weis, hab ich bis jetzt immer nur gehört, dass statisch gelinkte GTK+ Anwendungen nicht funktionieren. Ich hab es selber noch nicht ausprobiert. Du müsstest GTK+ selber als statisch compilieren.

    Das Problem dürfte sein, dass GTK+ manche DLLs erst zu Laufzeit lädt und dementsprechend DLLs braucht. Dieser Teil von GTK+ müsste ersetzt werden. Das ist aber nur spekulation. Es kann auch sein, dass die GTK+ entwickler diesen Fall vorgesehen haben.


Anmelden zum Antworten