cancel
Showing results for 
Search instead for 
Did you mean: 

Include problems (Cosmic compiler)

markbng
Associate II
Posted on January 19, 2005 at 11:28

Include problems (Cosmic compiler)

3 REPLIES 3
markbng
Associate II
Posted on January 18, 2005 at 09:58

Hello,

At the moment I am having some problems with compiling some c source. I use include ''user_var.h'' to include some global variables and defines, etc. But I can only call the include file from one c source-file. If I use the include statement in more than one c-file I get an error from the linker: ''symbol temp multiply defined''.

So I don't use the include anymore, but every c file has the variable declared as an external variable on top of the file (eg. 'extern char temp;'). Can I use the include statement instead? The include file has the '#ifndef USER_VAR_H', '#define USER_VAR_H' & '#endif' statements. What's wrong?

Thanks in advance for your help.

Kind regards,

Mark

[ This message was edited by: MarkBng on 18-01-2005 14:52 ]

alain2399
Associate II
Posted on January 18, 2005 at 13:14

One solution is to use the include file for defining the global variables but define each variable as EXTERN in my_include.h.

In the C file where you want the variables to defined (physical memory allocated to them), just before #include my_include.h, redefine EXTERN as nothing, the variable will then be allocated in the C file.

In all the other C file where you want he global variables defined in my_include.h to be known, redefine EXTERN as extern before #include my_include.h, then only the references of the variables will be given by the include file.

This will ensure that you have the same definitions of all gobal variables in all your project and there is no duplication of the global variables definitions.

Regards,

Alain

[ This message was edited by: Alaini on 18-01-2005 17:47 ]

luca239955_st
Associate III
Posted on January 19, 2005 at 11:28

Quote:

The include file has the '#ifndef USER_VAR_H', '#define USER_VAR_H' & '#endif' statements. What's wrong?

If you want to understand that, you need to run the preprocessor only and take a look at the output file (which is normally fed directly to the compiler):

cpst7 -i INCLUDE_PATH -e -o PREPROC_OUTFILE INPUTFILE.c

This will run the preprocessor only and send its output to PREPROC_OUTFILE. Looking at output file for different input files you will probably see that your global variables are actually passed on to the compiler in every input file, hence the error you get. You can go on to debug from there.

Hope it helps,

Luca (Cosmic)