Include

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
561 Views
rayhall
Contributor V

I am constantly having errors that something has been duplicated in another file.  I have global data (structure) that is declared in a file called main.h. Any other file that needs this data cannot see it, so I add #include "main.h" which causes errors.

 

It is like you have to write all you code in one huge file to use global values. Split the code into separate files and you cannot use them. Why is the language so restrictive. If not then how do you do it.

 

Attached is a simple test problem that shows the problem.

 

Ray.

Original Attachment has been moved to: Include_Test.zip

Labels (1)
0 Kudos
1 Solution
417 Views
ZhangJennie
NXP TechSupport
NXP TechSupport

in your code, you define variable "map" in the main.h file. thus each time you include the main.h in one c file, the "map" is defined. that's equals to you define "map" multi times in your project.

to correct it, you need define map in c file and  declare it as  external in .h file.

i modified your code. see attached.

View solution in original post

0 Kudos
3 Replies
418 Views
ZhangJennie
NXP TechSupport
NXP TechSupport

in your code, you define variable "map" in the main.h file. thus each time you include the main.h in one c file, the "map" is defined. that's equals to you define "map" multi times in your project.

to correct it, you need define map in c file and  declare it as  external in .h file.

i modified your code. see attached.

0 Kudos
417 Views
rayhall
Contributor V

Thank you.

I had tried that before and got errors. The other change you made was the to put typedef before the struct. With this it works.

Ray.

0 Kudos
417 Views
ZhangJennie
NXP TechSupport
NXP TechSupport

you are welcome!

0 Kudos