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)放在兩個不同的匯編,你會當你將它們鏈接得到一個錯誤的影響。這可能是有用的唯一原因是,如果你想驗證程序將在其他系統上,它總是以這種方式工作工作。(原諒我英語不好)。