[risolto] non riesco a compilare un programma che usa gtk

Linguaggi di programmazione: php, perl, python, C, bash e tutti gli altri.
Scrivi risposta
Avatar utente
RedTuxAgainstTheSystem
Scoppiettante Seguace
Scoppiettante Seguace
Messaggi: 433
Iscrizione: venerdì 29 settembre 2006, 19:53

[risolto] non riesco a compilare un programma che usa gtk

Messaggio da RedTuxAgainstTheSystem »

ciao ragazzi, provo a compilare un semplice helloworld con l'istruzione

g++ -o helloworld helloworld.cpp

ma l'output mi restituisce:
helloworld.cpp:1:21: error: gtk/gtk.h: Nessun file o directory
helloworld.cpp:5: error: variable or field ‘hello’ declared void
helloworld.cpp:5: error: ‘GtkWidget’ was not declared in this scope
helloworld.cpp:5: error: ‘widget’ was not declared in this scope
helloworld.cpp:6: error: ‘gpointer’ was not declared in this scope
helloworld.cpp:6: error: initializer expression list treated as compound expression
helloworld.cpp:7: error: expected ‘,’ or ‘;’ before ‘{’ token
helloworld.cpp:11: error: ‘gboolean’ does not name a type
helloworld.cpp:30: error: variable or field ‘destroy’ declared void
helloworld.cpp:30: error: ‘GtkWidget’ was not declared in this scope
helloworld.cpp:30: error: ‘widget’ was not declared in this scope
helloworld.cpp:31: error: ‘gpointer’ was not declared in this scope
helloworld.cpp:31: error: initializer expression list treated as compound expression
helloworld.cpp:32: error: expected ‘,’ or ‘;’ before ‘{’ token
helloworld.cpp: In function ‘int main(int, char**)’:
helloworld.cpp:40: error: ‘GtkWidget’ was not declared in this scope
helloworld.cpp:40: error: ‘window’ was not declared in this scope
helloworld.cpp:41: error: ‘button’ was not declared in this scope
helloworld.cpp:45: error: ‘gtk_init’ was not declared in this scope
helloworld.cpp:48: error: ‘GTK_WINDOW_TOPLEVEL’ was not declared in this scope
helloworld.cpp:48: error: ‘gtk_window_new’ was not declared in this scope
helloworld.cpp:55: error: ‘G_OBJECT’ was not declared in this scope
helloworld.cpp:56: error: ‘delete_event’ was not declared in this scope
helloworld.cpp:56: error: ‘G_CALLBACK’ was not declared in this scope
helloworld.cpp:56: error: ‘NULL’ was not declared in this scope
helloworld.cpp:56: error: ‘g_signal_connect’ was not declared in this scope
helloworld.cpp:65: error: ‘GTK_CONTAINER’ was not declared in this scope
helloworld.cpp:65: error: ‘gtk_container_set_border_width’ was not declared in this scope
helloworld.cpp:68: error: ‘gtk_button_new_with_label’ was not declared in this scope
helloworld.cpp:80: error: ‘gtk_widget_destroy’ was not declared in this scope
helloworld.cpp:81: error: ‘g_signal_connect_swapped’ was not declared in this scope
helloworld.cpp:84: error: ‘gtk_container_add’ was not declared in this scope
helloworld.cpp:87: error: ‘gtk_widget_show’ was not declared in this scope
helloworld.cpp:95: error: ‘gtk_main’ was not declared in this scope
perchè non trova le librerie per caso?
Ultima modifica di RedTuxAgainstTheSystem il martedì 25 settembre 2007, 1:42, modificato 1 volta in totale.
Un popolo senza odio non può vincere contro un nemico brutale.
Avatar utente
simo_magic
Rampante Reduce
Rampante Reduce
Messaggi: 9496
Iscrizione: lunedì 18 dicembre 2006, 21:37
Località: Piemonte

Re: non riesco a compilare un programma che usa gtk

Messaggio da simo_magic »

prova cercando in synaptic un pacchetto che si chiama più o meno
libgtk2-dev o qualcosa del genere
Avatar utente
RedTuxAgainstTheSystem
Scoppiettante Seguace
Scoppiettante Seguace
Messaggi: 433
Iscrizione: venerdì 29 settembre 2006, 19:53

Re: non riesco a compilare un programma che usa gtk

Messaggio da RedTuxAgainstTheSystem »

ma è gia installato... >:(
Un popolo senza odio non può vincere contro un nemico brutale.
Avatar utente
simo_magic
Rampante Reduce
Rampante Reduce
Messaggi: 9496
Iscrizione: lunedì 18 dicembre 2006, 21:37
Località: Piemonte

Re: non riesco a compilare un programma che usa gtk

Messaggio da simo_magic »

puoi postare il codice sorgente per favore?
Avatar utente
RedTuxAgainstTheSystem
Scoppiettante Seguace
Scoppiettante Seguace
Messaggi: 433
Iscrizione: venerdì 29 settembre 2006, 19:53

Re: non riesco a compilare un programma che usa gtk

Messaggio da RedTuxAgainstTheSystem »

certo!
#include

/* 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;
}
Un popolo senza odio non può vincere contro un nemico brutale.
Avatar utente
difesaparcosempione
Rampante Reduce
Rampante Reduce
Messaggi: 6031
Iscrizione: giovedì 27 luglio 2006, 19:06
Località: Torino
Contatti:

Re: non riesco a compilare un programma che usa gtk

Messaggio da difesaparcosempione »

Non trova includes e librerie.

Dovresti compilare con qualcosa del genere ..
( sto inventando, però è usato nei ambienti grafici ..)

g++ file1.cpp file2.cpp .. fileN.cpp 'xx-config --flags' 'xx-config --libs' -o eseguibile

Quindi devi trovare uno script/utility ( xx-config ) che intervistato fornisca le include e poi le librerie del tuo prodotto/IDE

ES. con i wx-widgets questa applicazione è wx-config !

Se vuoi compilare dando direttamente le includes e le librerie non ti passa +!

L'apice è un'apice e non l'apostrofo.

ciao
:)
Avatar utente
RedTuxAgainstTheSystem
Scoppiettante Seguace
Scoppiettante Seguace
Messaggi: 433
Iscrizione: venerdì 29 settembre 2006, 19:53

Re: non riesco a compilare un programma che usa gtk

Messaggio da RedTuxAgainstTheSystem »

up
Un popolo senza odio non può vincere contro un nemico brutale.
Avatar utente
__pablo__
Prode Principiante
Messaggi: 64
Iscrizione: sabato 15 settembre 2007, 22:02
Contatti:

Re: non riesco a compilare un programma che usa gtk

Messaggio da __pablo__ »

Il mio concetto di hello world è davvero più semplice... ma lo leggete il codice o solo taglia incolla?  (nono)
__pablo__

Web: http://paBlog2007.wordpress.com
IRC: chat.freenode.net #ubuntu-it #ubuntu-it-chat
Avatar utente
RedTuxAgainstTheSystem
Scoppiettante Seguace
Scoppiettante Seguace
Messaggi: 433
Iscrizione: venerdì 29 settembre 2006, 19:53

Re: non riesco a compilare un programma che usa gtk

Messaggio da RedTuxAgainstTheSystem »

a parte che è taglia e incolla  (rotfl) ma comunque penso che il problema prescinda dalla complessità del codice visto che non trova la libreria, l'importante è che il codice  sia corretto, e in ogni caso, se ti va siggeriscimi un helloworld più semplice! grazie per la risposta pablo!  (b2b)
Un popolo senza odio non può vincere contro un nemico brutale.
Avatar utente
paper0k
Rampante Reduce
Rampante Reduce
Messaggi: 7220
Iscrizione: lunedì 2 ottobre 2006, 13:39
Contatti:

Re: non riesco a compilare un programma che usa gtk

Messaggio da paper0k »

Codice: Seleziona tutto

g++ helloworld.cpp -o helloworld $( pkg-config gtk+-2.0 --libs --cflags)
;)
Chiunque può essere ragionevole, ma esser sani di mente è raro (Oscar Wilde)
Wiki|Blog|Twitter|Identi.ca|last.fm
Avatar utente
difesaparcosempione
Rampante Reduce
Rampante Reduce
Messaggi: 6031
Iscrizione: giovedì 27 luglio 2006, 19:06
Località: Torino
Contatti:

Re: non riesco a compilare un programma che usa gtk

Messaggio da difesaparcosempione »

up,
ma avevi visto che ti avevo risposto !!  :o

ciao
;D
Avatar utente
__pablo__
Prode Principiante
Messaggi: 64
Iscrizione: sabato 15 settembre 2007, 22:02
Contatti:

Re: non riesco a compilare un programma che usa gtk

Messaggio da __pablo__ »

Guarda che scherzavo... mi ha fatto ridere il fatto che l'hello world che hai presentato non è molto un hello world da chi inizia a programmare... è più da chi già sa usare compilatore e linker e ha un'idea di ciò che il codice fa... voglio dire... hai esortito divendo che non trovava la blah blah... ma per chi almeno ha usato una volta un compilatore dovrebbe capire il perchè e come evitarlo!!! Ma credimi non volevo essere offensivo.. se così mi sono rivelato allora mi scuso!

Cmq... ti consiglio di iniziare con qualcosa di secco e asciutto... cerca un manuale per principianti che ti soddisfi, almeno imparerai ad usare gli strumenti nel modo giusto e di evitare di fare le cose a tentativi... si si... secondo me ti conviene così... se parti dalle basi poi risolvere un problema simile ti verà più semplice... ed oltre tutto capirai quello che stai facendo invece di fare le cose in un modo solo perchè funzionano e non sapere poi del perchè funzionano!!!

Ciao
__pablo__

Web: http://paBlog2007.wordpress.com
IRC: chat.freenode.net #ubuntu-it #ubuntu-it-chat
Avatar utente
RedTuxAgainstTheSystem
Scoppiettante Seguace
Scoppiettante Seguace
Messaggi: 433
Iscrizione: venerdì 29 settembre 2006, 19:53

Re: non riesco a compilare un programma che usa gtk

Messaggio da RedTuxAgainstTheSystem »

Guarda che scherzavo... mi ha fatto ridere il fatto che l'hello world che hai presentato non è molto un hello world da chi inizia a programmare... è più da chi già sa usare compilatore e linker e ha un'idea di ciò che il codice fa... voglio dire... hai esortito divendo che non trovava la blah blah... ma per chi almeno ha usato una volta un compilatore dovrebbe capire il perchè e come evitarlo!!! Ma credimi non volevo essere offensivo.. se così mi sono rivelato allora mi scuso!

Cmq... ti consiglio di iniziare con qualcosa di secco e asciutto... cerca un manuale per principianti che ti soddisfi, almeno imparerai ad usare gli strumenti nel modo giusto e di evitare di fare le cose a tentativi... si si... secondo me ti conviene così... se parti dalle basi poi risolvere un problema simile ti verà più semplice... ed oltre tutto capirai quello che stai facendo invece di fare le cose in un modo solo perchè funzionano e non sapere poi del perchè funzionano!!!

Ciao
ma si, ma che offeso! come ti dicevo però a me l'unica cosa che importava era la correttezza del codice, perchè dovevo solo provare il compilatore!
up,
ma avevi visto che ti avevo risposto !!
si, avevo visto, è solo che mi sembrava troppo complesso! cmq grazie! e grande grande grande comitato!
g++ helloworld.cpp -o helloworld $( pkg-config gtk+-2.0 --libs --cflags)
sintetico e enormemente efficace. Funziona! Metto risolto nel titolo. Ma non c'è un modo per automatizzare l'inclusione della libreria nel compilatore?

Grazie a tutti...
Un popolo senza odio non può vincere contro un nemico brutale.
Avatar utente
difesaparcosempione
Rampante Reduce
Rampante Reduce
Messaggi: 6031
Iscrizione: giovedì 27 luglio 2006, 19:06
Località: Torino
Contatti:

Re: non riesco a compilare un programma che usa gtk

Messaggio da difesaparcosempione »

Ti conviene mettere risolto a questo TOPO e semmai aprirne uno nuovo!
ciao
:D
Avatar utente
mastyx
Prode Principiante
Messaggi: 137
Iscrizione: mercoledì 20 dicembre 2006, 12:44

Re: [risolto] non riesco a compilare un programma che usa gtk

Messaggio da mastyx »

Mamma mia
Ma questo "helloworld" su quale manuale l'hai preso, perché se il programma per iniziare e cosi.... figurati il resto arriva a 100000 pagine.

Buona programmazione a tutti.
Avatar utente
SoNKkK
Prode Principiante
Messaggi: 163
Iscrizione: mercoledì 25 aprile 2007, 10:57

Re: non riesco a compilare un programma che usa gtk

Messaggio da SoNKkK »

Senza tutto quel bordello sarebbe

Codice: Seleziona tutto

#include <gtk/gtk.h>

static void hello( GtkWidget *widget,
                   gpointer   data )
{
    g_print ("Hello World\n");
}

static gboolean delete_event( GtkWidget *widget,
                              GdkEvent  *event,
                              gpointer   data )
{

    g_print ("delete event occurred\n");

    return TRUE;
}

static void destroy( GtkWidget *widget,
                     gpointer   data )
{
    gtk_main_quit ();
}

int main( int   argc,
          char *argv[] )
{

    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    

    g_signal_connect (G_OBJECT (window), "delete_event",
		      G_CALLBACK (delete_event), NULL);

    g_signal_connect (G_OBJECT (window), "destroy",
		      G_CALLBACK (destroy), NULL);
    
    gtk_container_set_border_width (GTK_CONTAINER (window), 10);
    
    button = gtk_button_new_with_label ("Hello World");
    
    g_signal_connect (G_OBJECT (button), "clicked",
		      G_CALLBACK (hello), NULL);
    
    g_signal_connect_swapped (G_OBJECT (button), "clicked",
			      G_CALLBACK (gtk_widget_destroy),
                              G_OBJECT (window));
    
    gtk_container_add (GTK_CONTAINER (window), button);
    
    gtk_widget_show (button);
    
    gtk_widget_show (window);

    gtk_main ();
    
    return 0;
}
Scrivi risposta

Ritorna a “Programmazione”

Chi c’è in linea

Visualizzano questa sezione: 0 utenti iscritti e 3 ospiti