ios 构建失败:ld:重复符号 _OBJC_CLASS_$_Algebra5FirstViewController

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10435213/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 18:15:09  来源:igfitidea点击:

build failed with: ld: duplicate symbol _OBJC_CLASS_$_Algebra5FirstViewController

objective-ciosxcodeios5.1

提问by Joe Shamuraq

I am getting this error suddenly when running my app via iPhone simulator:

通过 iPhone 模拟器运行我的应用程序时,我突然收到此错误:

clang: error: linker command failed with exit code 1 (use -v to see invocation):

ld: duplicate symbol _OBJC_CLASS_$_Algebra5FirstViewController in .../Algebra5-anwcuftojtxtgkfootneeeqhwztj/Build/Intermediates/Algebra5.build/Debug-iphonesimulator/Algebra5.build/Objects-normal/i386/ExercisesViewController.o and .../Algebra5-anwcuftojtxtgkfootneeeqhwztj/Build/Intermediates/Algebra5.build/Debug-iphonesimulator/PSLE Algebra5.build/Objects-normal/i386/PSLE_Algebra5FirstViewController.o for architecture i386

clang:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用):

ld: 重复符号 _OBJC_CLASS_$_Algebra5FirstViewController 在 .../Algebra5-anwcuftojtxtgkfootneeeqhwztj/Build/Intermediates/Algebra5.build/Debug-iphonesimulator/Algebra5.build/Objects-normal/i386/ExercisesViewController.o/ExercisesViewController.5/jjwzgteqneeqhwztj/Build/Intermediates Build/Intermediates/Algebra5.build/Debug-iphonesimulator/PSLE Algebra5.build/Objects-normal/i386/PSLE_Algebra5FirstViewController.o 架构 i386

What is it all about?

这是什么一回事呢?

采纳答案by J_D

It look like the class Algebra5FirstViewController is compile multiple time.

看起来类 Algebra5FirstViewController 被多次编译。

Can you make sure that the .m and .mm is only included once in your project sources in Xcode? You can also confirm this by checking in the compile log (last icon at the right, next to the breakpoints icon) and see that confirm that it is only compiled once.

你能确保 .m 和 .mm 在 Xcode 的项目源中只包含一次吗?您还可以通过检查编译日志(右侧最后一个图标,断点图标旁边)来确认这一点,并确认它仅编译一次。

Also, if this class is part of a library that you link against and you have a class with the same name, you could have the same error.

此外,如果此类是您链接的库的一部分,并且您有一个同名的类,则可能会出现相同的错误。

Finally, you can try a clean and rebuild, just in case the old object files are still present and there is some junk in the compiled files. Just in case...

最后,您可以尝试清理和重建,以防旧的目标文件仍然存在并且编译文件中有一些垃圾。以防万一...

EDIT

编辑

I also note that the second reference is made in the file for ExercisesViewController. Maybe there is something in this file. Either you #imported the Algebra5FirstViewController file instead of the .h, or the ExercisesViewController has @implementation (Algebra5FirstViewController) instead of @implementation (ExercisesViewController), or there was some junk with this file that will cleaned with a Clean an Rebuild.

我还注意到,第二个引用是在文件中的练习视图控制器。也许这个文件里有东西。要么你#imported Algebra5FirstViewController 文件而不是.h,或者ExtractionsViewController 有@implementation (Algebra5FirstViewController) 而不是@implementation (ExercisesViewController),或者这个文件中有一些垃圾,将使用Clean an Rebuild 来清理。

回答by Andreas Ley

That can happen if the same .m file is referenced multiple times in your target's "Compile Sources" section in "Build Phases". Remove duplicate entries and you should be fine.

如果在“构建阶段”的目标的“编译源”部分中多次引用同一个 .m 文件,就会发生这种情况。删除重复的条目,你应该没问题。

回答by toblerpwn

also had this problem by declaring a const * NSStringin the header file (incorrectly) instead of the implementation file (correctly)

通过const * NSString在头文件(不正确)而不是实现文件(正确)中声明 a 也有这个问题

回答by user441669

I got this issue because I accidentally imported the .m instead of the .h. Hope reading this saves someone with same problem some time.

我遇到这个问题是因为我不小心导入了 .m 而不是 .h。希望阅读这篇文章可以帮助遇到同样问题的人一段时间。

回答by Jayprakash Dubey

I had same problem. Got it solved!

我有同样的问题。解决了!

If you have imported any files into project then check .m (main) file for same does exists in Targets (Project Name) -> Build Phases -> Compile Sources.

如果您已将任何文件导入项目,则检查 .m(主)文件是否存在于目标(项目名称)-> 构建阶段-> 编译源中。

If file does not exists then include it using (+) Add button shown. Also, if duplicate files exists (if any) then delete it.

如果文件不存在,则使用显示的 (+) 添加按钮将其包含在内。此外,如果存在重复文件(如果有),则将其删除。

Now press cmd+shift+k to clean the project. New Build should not display this error.

现在按 cmd+shift+k 来清理项目。New Build 不应显示此错误。

enter image description here

在此处输入图片说明

回答by Eric

I got a similar error when adding files from another project, like @paiego explained. My error was that I didn't check "Add to targets". As explained above, I deleted the references and added the files again but this time checking "Add to targets".

从另一个项目添加文件时,我遇到了类似的错误,就像@paiego 解释的那样。我的错误是我没有选中“添加到目标”。如上所述,我删除了引用并再次添加了文件,但这次选中了“添加到目标”。

回答by zeeawan

I was getting similar error and I got it resolved this way.

我遇到了类似的错误,我以这种方式解决了。

Try to set Build Active Architecture Only to NO for 'Pods' project and your app's target

尝试将“Pods”项目和您的应用程序目标的“仅构建活动架构”设置为“否”

回答by paiego

In one case, I saw this error when dragging a new class' .h and .m into the project. The only solution I found was to remove the references to these files and then add them back via the project menu.

在一种情况下,我在将新类的 .h 和 .m 拖入项目时看到了此错误。我找到的唯一解决方案是删除对这些文件的引用,然后通过项目菜单将它们添加回来。

回答by Huy Hóm H?nh

I met it when import a ViewController.m in TableViewController. Try to delete '#import "ViewController.m"' if it exited. Hope this help!

我在 TableViewController 中导入 ViewController.m 时遇到了它。如果退出,请尝试删除 '#import "ViewController.m"'。希望这有帮助!

回答by Jazzmine

I found this articlethat provided a solution for me. It pertains to Xcode 7 where the default for No Common Blocks is Yes rather than No in previous versions.

我发现这篇文章为我提供了解决方案。它适用于 Xcode 7,其中 No Common Blocks 的默认值是 Yes 而不是之前版本中的 No。

This is a quote from the article:

这是文章中的一段话:

The problem seems to be that the "No common blocks" in the "Apple LLVM 6.1 - Code Generation" section in the Build settings pane is set to Yes, in the latest version of Xcode.

问题似乎是在最新版本的 Xcode 中,Build settings 窗格中“Apple LLVM 6.1 - Code Generation”部分中的“No common blocks”设置为 Yes。

This caused what I will describe as circular references where a class that was included in my Compile Sources was referenced via a #import in another source file (appDelegate.m). This caused duplicate blocks for variables that were declared in the original base class.

这导致了我将描述为循环引用的情况,其中包含在我的编译源中的类是通过另一个源文件 (appDelegate.m) 中的 #import 引用的。这导致在原始基类中声明的变量出现重复块。

Changing the value to No immediately enabled my app to compile and resolved my problem.

将值更改为 No 立即使我的应用程序能够编译并解决我的问题。