Include

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 
1,102件の閲覧回数
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 解決策
958件の閲覧回数
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 返答(返信)
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 件の賞賛
返信
958件の閲覧回数
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 件の賞賛
返信
958件の閲覧回数
ZhangJennie
NXP TechSupport
NXP TechSupport

you are welcome!

0 件の賞賛
返信