iOS duplicate symbol 变量 in 类名 报错

该错误信息是我在一个.h文件里申明了公共变量,然后在其他类里重复使用。

Build Settings ->No Common Blocks默认为YES,编译器就报错了,需要修改Build Settings里的No Common Blocks为NO。

 

NO Common Blocks 是什么?

 官方的解释是:

    In C, allocate even uninitialized global variables in the data section of the object file, rather than generating them as common blocks. This has the effect that if the same variable is declared (without extern ) in two different compilations, you will get an error when you link them. The only reason this might be useful is if you wish to verify that the program will work on other systems which always work this way.

    在C语言中,在目标文件的数据段分配甚至未初始化的全局变量,而不是生成它们作为公共块。这样做,如果同一个变量被声明(没有extern)放在两个不同的汇编,你会当你将它们链接得到一个错误的影响。这可能是有用的唯一原因是,如果你想验证程序将在其他系统上,它总是以这种方式工作工作。

posted @ 2016-12-19 09:42  韦韦韦  阅读(374)  评论(0编辑  收藏  举报