为什么XCode会出现重复符号错误? [英] Why is XCode flaky about throwing duplicate symbol errors?

查看:520
本文介绍了为什么XCode会出现重复符号错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有两个目标的XCode 6项目 - iOS 8应用程序和iOS 8扩展程序。我在两个目标之间共享一个常量文件。

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.

我错误地在标头中声明了一个没有extern或静态前缀的const int,这导致了重复的符号链接器错误。

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.

此错误声明已存在于项目的过去几次修订中,并且常量标题自第一天起已包含在MULTIPLE文件中。

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.

为什么然后,我最近才开始收到错误 - 在我通过删除Main.storyboard对项目文件进行更改之后 - 这也只是在模拟器构建上?

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?

注意:之前发生过


我从项目文件中删除了一个未使用的Main.storyboard,然后立即开始收到此链接器错误。我知道现在不应该发生这个错误,因为相关的常数已经使用了很长时间。

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.

无论如何我修正了错误(通过将const声明为extern而不是) ,但现在开始遇到其他一些错误。

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

我现在确信代码没有任何问题,而且只是XCode错了。所以为了测试I ONCE AGAIN删除了Main.storyboard,并且奇怪的错误(抱歉我没有记录)又回来了,代码没有变化。

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.

为了进一步确认,我在同一台机器上检查了一个完整的事先提交(它完美无缺,并且仍然有Main.storyboard)。这一次,在没有对代码,项目或Main.storyboard进行任何更改的情况下,我看到了相同的错误。

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.

这证实我的实际没有任何问题pbxproj和源文件,但数据XCode中的某些问题已缓存(某处)。

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).

请注意,清除DerivedData文件夹也无济于事。

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

迂回点是,肯定是XCode有问题是突然抛出错误还是不抛弃它。但我正在检查是否可能有另一个逻辑解释为什么XCode突然似乎改变它的行为。

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.

推荐答案

检查您是否错误地 #import 编辑了一个 .m 文件,而不是 .H 。这导致过去我的重复符号错误。

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.

这篇关于为什么XCode会出现重复符号错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆