ric*_*chy 0 c objective-c header-files ios
可能重复:
标头变量的obj-c重复符号
我的项目中有多个.m和.mm文件.我可以在我喜欢的.m文件中包含这个.h文件(那个dosent有一个相应的.m或.mm文件)但是当我把它包含在一个以上的.mm文件中时,我得到了重复的符号链接器错误.
同样在.h文件中,我用预处理器命令包围了内容(这些是在obj-c中被尊重吗?)这里看起来像是这样的:
#ifndef _CONFIG_H_
#define _CONGIF_H_
CGFloat WIDTH, HEIGHT;
// other similar code...
#endif
Run Code Online (Sandbox Code Playgroud)
我在WIDTH和HEIGHT上得到重复的符号错误
You should add
extern
Run Code Online (Sandbox Code Playgroud)
keyword before CGFloat declaration in the header, and define the variables without extern in the .m file to avoid defining your variables in multiple places.
In the header:
extern CGFloat WIDTH, HEIGHT;
Run Code Online (Sandbox Code Playgroud)
In a .m file (one of them, any one)
CGFloat WIDTH, HEIGHT;
Run Code Online (Sandbox Code Playgroud)