Include

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决
1,103 次查看
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

标签 (1)
0 项奖励
回复
1 解答
959 次查看
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 项奖励
回复
3 回复数
960 次查看
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 项奖励
回复
959 次查看
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 项奖励
回复
959 次查看
ZhangJennie
NXP TechSupport
NXP TechSupport

you are welcome!

0 项奖励
回复