Why is XCode flaky about throwing duplicate symbol errors?

强颜欢笑 提交于 2019-12-07 06:39:43

问题


I have an XCode 6 project with two targets - an iOS 8 app and an iOS 8 extension. I share a constants file across both targets.

I made the mistake of declaring a const int without an extern or static prefix in the header, which resulted in the duplicate symbols linker error.

This erroneous declaration has existed for the past several revisions of the project, and the constants header has been included in MULTIPLE files since day one.

Why then, did I start getting the error only recently - after I made a change to the project file by removing the Main.storyboard - and that too ONLY on the simulator build?

Note: This has happened before


Further background on when the error started occurring:

I removed an unused Main.storyboard from the project file, and immediately after, started getting this linker error. I knew this error should not be occurring now, since the relevant constant had been used for ages.

I fixed the error anyway (by declaring the const as an extern instead), but now started getting some other errors.

I was now convinced there wasn't anything wrong with the code, and it was just XCode mucking up. So to test I ONCE AGAIN removed the Main.storyboard, and the weird errors (sorry I don't have a record) were back again, with zero changes to code.

To confirm further, I checked out a complete prior commit (which had worked flawlessly, and still had the Main.storyboard) on the same machine. This time, without any changes to the code, the project or Main.storyboard, I saw the same errors.

This confirmed that there wasn't any problem with my actual pbxproj and source files, but some problem in the data XCode had cached (somewhere).

Note that clearing the DerivedData folder didn't help either.

The roundabout point being, XCode definitely seems to be at fault whether for throwing the error suddenly or not throwing it all this while. But I'm checking if there could be another logical explanation for why XCode suddenly seemed to "change" its behavior.


回答1:


Just check that you haven't #imported a .m file by mistake, instead of a .h. This has caused the duplicate symbol error for me in the past.



来源:https://stackoverflow.com/questions/25822142/why-is-xcode-flaky-about-throwing-duplicate-symbol-errors

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!