Re: C/GTK question
- From: John Vetterli <jvetterli linux ca>
- To: Gtk AppDev Mailing List <gtk-app-devel-list gnome org>
- Subject: Re: C/GTK question
- Date: Sat, 17 Jun 2006 01:55:35 -0400 (EDT)
On Thu, 15 Jun 2006, Matías Torres wrote:
... This is what i did:
global.c
GtkWidget *mainWindow
gtkarch1.c gtkarch2.c gtkarch3.c gtkarch4.c
/* Al this files uses the mainWindow variable, this is what i do:
gtkarchX.c
#include global.c
GtkWidget *mainWindow */
ant then the main.c file which looks like this:
main.c
#include "gtkarch1.c"
#include "gtkarch2.c"
#include "gtkarch3.c"
But the compiler gives me an error, which I understand but i don't know how
to solve it, that says that i'm redefining the variables declared in
global.c in each gtkarchX.c
So............ Help? please?
You need to use the "extern" keyword. Each time you have
GtkWidget *mainWindow;
in your source, you are instructing the compiler to create a new variable
called mainWindow. What you need to do is to use
extern GtkWidget *mainWindow;
which tells the compiler that the variable called mainWindow exists
somewhere, somewhere else the program.
Also, a good technique is to put common declarations in a header file. I
would suggest creating a file called "global.h", which contains:
extern GtkWidget *mainWindow;
Then include "global.h" in every source file which needs to access your
global variable. Don't forget to actually create the variable in one of
your source files (i.e. use "GtkWidget *mainWindow" without the "extern"
once and only once).
HTH
JV
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]