UP主今天升级了XCode到8之后,打开了工程就崩溃了。。。,看错误代码
duplicate symbol _myBlock in:
/Users/****/Library/Developer/Xcode/DerivedData/****-gixcunlvzgbiameffodyrjucpldm/Build/Intermediates/****.build/Debug-iphoneos/****.build/Objects-normal/arm64/PCCircleInfoView.o
/Users/****/Library/Developer/Xcode/DerivedData/****-gixcunlvzgbiameffodyrjucpldm/Build/Intermediates/****.build/Debug-iphoneos/****.build/Objects-normal/arm64/ShareApp.o
duplicate symbol _myBlock in:
/Users/****/Library/Developer/Xcode/DerivedData/****-gixcunlvzgbiameffodyrjucpldm/Build/Intermediates/****.build/Debug-iphoneos/****.build/Objects-normal/arm64/PCCircleInfoView.o
/Users/****/Library/Developer/Xcode/DerivedData/****-gixcunlvzgbiameffodyrjucpldm/Build/Intermediates/****.build/Debug-iphoneos/****.build/Objects-normal/arm64/ModifyAddrModelControl.o
。。。。。。。。中间省略好多行
ld: 247 duplicate symbols for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
????247个错误
分析了一下,是PCCircleInfoView这个文件引入重复,和其他247个文件有冲突,但是神奇的是。Complie Souces 引入了248个文件,也就是我这个文件和所有文件有冲突。
凌乱的我就在网上开始找问题,后来看到一种可能,是因为这个文件中的某一变量或者某一方法名和其他某一文件的变量名或者方法有重复同名,就找到了解决方法:
在Build Setting里面 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)放在两个不同的汇编,你会当你将它们链接得到一个错误的影响。这可能是有用的唯一原因是,如果你想验证程序将在其他系统上,它总是以这种方式工作工作。(原谅我英语不好)。