I am trying to use the folowing # define statement
//-------------------------------------
#idndef _THISFILE_
#define _THISFILE_
:
//some definitions here
:
#endif
//-----------------------------------
and use this header file in various .C files, and to my surprise I get the "Multiple definition" error and I am wondering if there is any option in the IDE i have to setup? Could you please explain this and let me know about a possible workaround as well.
I also have problem with defining a structure as "extern" while I have defined it as a "typdef" of a structure in another file? the compiler complains about illigal definition of the extern!? is there any other way to define this with no error?
Thanks;
Hello Geek19
The define statement you mentioned protects a single compilation unit (single .c file) from including the multiple definitions of the same header file.
I assume you are able to compile but there is a linker error right?
Can you double check if the header files included does not contain any object definition?
e.g. "thisfile.h":
--------------------
#idndef _THISFILE_
#define _THISFILE_
...
int my_object = 10;
...
#endif
In such particular case "my_object" is allocated in each .c file that includes thisfile.h.
Regarding the extern struct see the example below that should work:
e.g. "thisfile.h":
--------------------
#idndef _THISFILE_
#define _THISFILE_
...
typedef struct
{
int a;
int b;
}tMyStruct;
extern tMyStruct my_struct;
// header file includes just extern declaration ( type tMyStruct must be available in .h file or included from separate .h file)
...
#endif
thisfile.c
-----------
#include "thisfile.h"
tMyStruct my_struct; // here the memory is allocated to the struct variable
...
If this does not help please post some code snippets...
Stanish