ios Xcode 4.6 上的 Mach-O 链接器错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14990632/
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 22:22:46  来源:igfitidea点击:

Mach-O Linker Error on Xcode 4.6

iosxcodexcode4.6

提问by user1253582

I have an iOS app on Xcode 4.6 and when I recently tried to build and run in the iPhone 6.1 simulator I got a "Mach-O Linker Error." It continued to say:

我在 Xcode 4.6 上有一个 iOS 应用程序,当我最近尝试在 iPhone 6.1 模拟器中构建和运行时,我遇到了“Mach-O 链接器错误”。它继续说:

ld: 17 duplicate symbols for architecture i386 clang: error: linker command failed with exit code 1 (use -v to see invocation)

ld:架构 i386 clang 的 17 个重复符号:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)

Does anyone know how to solve this?

有谁知道如何解决这个问题?

Thanks so much!

非常感谢!

回答by edzio27

Just go to "Build Phases" -> "Compile Sources" and look for duplicate of classes.

只需转到“构建阶段”->“编译源”并查找类的重复项。

回答by Arnaud Nelissen

Check if you have "*.m" files in your #import! It appears that was my mistake...

检查您是否有“ * .M”文件在你的#import!看来是我的错...

回答by Azhar

  1. Quit Xcode
  2. Restart the System
  3. Select Xcode -> Preferences -> Locations
  4. In Locations, you will see 'Derived Data'. Click on the arrow icon right next to the path.
  5. This will open a folder containing 'Derived Data', delete it.
  6. Clean the Product and Run

    if still not works then

    Build Settings > Enable Bitcode > Noenter image description here

  1. 退出 Xcode
  2. 重启系统
  3. 选择 Xcode -> 首选项 -> 位置
  4. 在位置中,您将看到“派生数据”。单击路径旁边的箭头图标。
  5. 这将打开一个包含“派生数据”的文件夹,将其删除。
  6. 清洁产品并运行

    如果还是不行

    构建设置 > 启用位码 > 否在此处输入图片说明

回答by Yerkezhan

In my example, I declared

在我的例子中,我声明

extern NSString const *keyString

in two different files. I renamed one of them and it solved my problem.

在两个不同的文件中。我重命名了其中之一,它解决了我的问题。

回答by Rishab

In my case it was constants.

就我而言,它是常量。

NSString *const cellID = @"cellID";

This line was written in two .m files. After appending statickeyword at the start the problem was resolved.

这一行写在两个 .m 文件中。在static开始时附加关键字后,问题解决了。

This issue can be recreated in a new project too. You would think that defining constants in the different .m files won't have any effect as they are private. But I don't know how the compiler is handling stuffs behind the scene. On top of that when you tap the issue from issue navigator it doesn't open up a page in the editor like it does for any other issue. Really frustrating.

这个问题也可以在新项目中重新创建。您会认为在不同的 .m 文件中定义常量不会有任何影响,因为它们是私有的。但我不知道编译器是如何处理幕后的东西的。最重要的是,当您从问题导航器中点击问题时,它不会像处理任何其他问题那样在编辑器中打开页面。真令人沮丧。

回答by ElonChan

If you want to change a value both in tow different class. Do remember to mark with static keywords.

如果你想在两个不同的类中更改一个值。请记住用静态关键字标记。

or the clang will throw such error below without any value interpretation。

否则clang会在没有任何价值解释的情况下抛出这样的错误。

Apple Mach-O Linker Error clang: error: linker command failed with exit code 1

Apple Mach-O 链接器错误 clang:错误:链接器命令失败,退出代码为 1

回答by Alex

When you refactor a class func you will also sometimes get this error. Just go to Product-> Clean and rebuild.

重构类 func 时,有时也会出现此错误。只需转到产品-> 清洁和重建。

回答by Khaled Barazi

I am not sure I can give you a solution but I will share an answer since the same happened to me on xCode 4.6 as well. I added a C class header and implementation file and included them in main. I then decided to delete that new C Class header and implementation. When I ended up adding a new c class/header again with the same name and function calls, I ended up with your error.

我不确定我可以给你一个解决方案,但我会分享一个答案,因为我在 xCode 4.6 上也发生了同样的事情。我添加了一个 C 类头文件和实现文件,并将它们包含在 main.c 中。然后我决定删除那个新的 C 类头文件和实现。当我再次添加一个具有相同名称和函数调用的新 c 类/头文件时,我以您的错误告终。

Frankly, this might be a bug. The only and fastest way I fixed it was to start a new project and pull all the classes in.

坦率地说,这可能是一个错误。我修复它的唯一和最快的方法是开始一个新项目并拉入所有类。

回答by ColossalChris

Make sure you don't have non-instant methods with the same name in multiple classes (So for example if I have two viewcontrollers that are pretty similar so to move quickly I copy and paste the code from one viewcontroller to the second and they both have methods called the same thing like: NSMutableString *filteredStringFromStringWithFilter(NSString *string, NSString *filter)) then the app gets confused which of those methods to use since they are both available, RENAME IT on the second class and change any calls to that method on that class and you've removed the confusion. Don't we all want things to be more clear!

确保在多个类中没有同名的非即时方法(例如,如果我有两个非常相似的视图控制器,以便快速移动,我将代码从一个视图控制器复制并粘贴到第二个视图控制器,它们都具有调用相同内容的方法,例如: NSMutableString *filteredStringFromStringWithFilter(NSString *string, NSString *filter)) 然后应用程序会混淆使用哪些方法,因为它们都可用,在第二个类中重命名 IT 并更改对该方法的任何调用该类上的方法,您已经消除了混乱。我们不是都希望事情变得更清楚吗!

回答by Vinicius Carneiro

Build Phases" -> "Compile Sources" click the button "Validate Settings"

Build Phases” -> “Compile Sources” 点击“Validate Settings”按钮

it's will fix your project

它会修复你的项目