Extern vars unresolved at link
-
I have a program with the following defined in a header file that is included in many files. I need the var to be global so I have this in the header file: Global.h typedef struct _D2N_GLBL_STRUCT { long runways_line_pos; ... }D2N_GLBL_STRUCT; extern D2N_GLBL_STRUCT *D2N_GLBL; .cpp D2N_GLBL->runway... = -1; I get linker errors saying it is undefined or already defined in files that I've include the global.h file. What am I doing wrong? Thanks for any help
-
I have a program with the following defined in a header file that is included in many files. I need the var to be global so I have this in the header file: Global.h typedef struct _D2N_GLBL_STRUCT { long runways_line_pos; ... }D2N_GLBL_STRUCT; extern D2N_GLBL_STRUCT *D2N_GLBL; .cpp D2N_GLBL->runway... = -1; I get linker errors saying it is undefined or already defined in files that I've include the global.h file. What am I doing wrong? Thanks for any help
You need to include global variables in one source file without the "extern" keyword. One way to do this is:
#ifndef INIT_MY_GLOBAL extern #endif D2N_GLBL_STRUCT *D2N_GLBL;
then in your main .cpp file use:#define INIT_MY_GLOBAL #include <global.h>
Having said all that globals are a realy bad idea.:( Neville Franks, Author of ED for Windows www.getsoft.com and coming soon: Surfulater www.surfulater.com -
I have a program with the following defined in a header file that is included in many files. I need the var to be global so I have this in the header file: Global.h typedef struct _D2N_GLBL_STRUCT { long runways_line_pos; ... }D2N_GLBL_STRUCT; extern D2N_GLBL_STRUCT *D2N_GLBL; .cpp D2N_GLBL->runway... = -1; I get linker errors saying it is undefined or already defined in files that I've include the global.h file. What am I doing wrong? Thanks for any help
In the global.h you have extern D2N_GLBL_STRUCT *D2N_GLBL; Did you put D2N_GLBL_STRUCT *D2N_GLBL; in one of the .cpp file?? if you dont do it, it will give you linker error.
P.R.A.K.A.S.H