Xcode,重复符号 _main

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

Xcode, Duplicate symbol _main

xcode

提问by huggie

I have duplicate symbol _main.

我有重复的符号_main。

The problem is it says "Duplicate symbol _main in /Users/.../i386/main-B9843B6026D6EFA4.o and /Users/.../i386/main-B9843B6026D6EFA4.o", the XXX and XXX are actually the same .o file. I don't know why it thinks it's duplicate symbol when it's the same .o?!

问题是它说“/Users/.../i386/main-B9843B6026D6EFA4.o和/Users/.../i386/main-B9843B6026D6EFA4.o中的重复符号_main”,XXX和XXX实际上是一样的。文件。我不知道为什么它认为它是相同的 .o 时它是重复的符号?!

Any help appreciated, thanks.

任何帮助表示赞赏,谢谢。

回答by huggie

Ah..I figure out it's that I have multiple entries under Targets/Compiled Sources ( in newer XCode it's under Build Phases/Compile Sources ). I removed them and the problem is solved. The multiple entry thing probably has to do with Git merge.

啊..我发现我在 Targets/Compiled Sources 下有多个条目(在较新的 XCode 中,它位于 Build Phases/Compile Sources 下)。我删除了它们,问题就解决了。多条目的事情可能与 Git 合并有关。

回答by dvkch

It appeared that in my case I was importing a .m file instead of its .h counterpart. Solved by editing

似乎在我的情况下,我正在导入一个 .m 文件而不是它的 .h 对应文件。通过编辑解决

#import "Tools.m"

into

进入

#import "Tools.h"

回答by Stefan

I also had this problem and it was caused by code I imported from another project. I did a grep for "int main" in my project directory:

我也有这个问题,它是由我从另一个项目导入的代码引起的。我在我的项目目录中为“int main”做了一个 grep:

grep -nr "int main" .

and found

并发现

./main.m:13:int main(int argc, char *argv[])
./IMPORTED_DIR/main.m:13:int main(int argc, char *argv[])

the IMPORTED_DIR contained the extra main.m that was causing the error for me

IMPORTED_DIR 包含导致我错误的额外 main.m

I removed that file from the Project -> Targets -> Build phases -> Compile sources list and then it compiled

我从项目 -> 目标 -> 构建阶段 -> 编译源列表中删除了该文件,然后编译

回答by Arbaz Shaikh

I was facing the same issue with using two third party framework. (AppLovin and Flurry) And I came to know that by removing "all_load" from "Other Linker Flags" in build settings.

我在使用两个第三方框架时遇到了同样的问题。(AppLovin 和 Flurry)我通过在构建设置中从“其他链接器标志”中删除“all_load”来了解这一点。

回答by Kas1a

I had the same problem opening a project, that was created with Xcode 4.0.2, with Xcode 4.1. I simply solved by clicking on "Modernize Project" (Editor/Modernize Project). This procedure automatically removed all duplicates.

我在打开一个项目时遇到了同样的问题,该项目是使用 Xcode 4.0.2 创建的,使用 Xcode 4.1。我只是通过单击“现代化项目”(编辑器/现代化项目)来解决。此过程会自动删除所有重复项。

回答by altosh

If still have a problem, try to search like this: "int main(", and remove those files except main.m

如果还有问题,尝试这样搜索:"int main(",并删除除main.m之外的那些文件

回答by InvulgoSoft

Just got this problem myself, but after reading huggie's solution which did lead me on the right track, I was left a bit confused. So current solution in Xcode: Choose project, target -> build phases and click validate settings

我自己刚遇到这个问题,但在阅读了 Huggie 的解决方案后,它确实引导我走上了正确的道路,我有点困惑。所以Xcode中的当前解决方案:选择项目,目标->构建阶段并单击验证设置

Then Xcode will auto fix its own mistake. It is always nice when the tools tries to stop your progress ;)

然后Xcode会自动修复它自己的错误。当工具试图阻止你的进步时,总是很好;)

回答by Pierre-Francoys Brousseau

In my case, I declared an NSString in my constants file (imported by many classes) but forgot to define it as static!!

就我而言,我在我的常量文件(由许多类导入)中声明了一个 NSString 但忘记将其定义为静态!!

e.g. NSString* PARAMS = @"paramA";should be: static NSString* PARAMS = @"paramA";

例如 NSString* PARAMS = @"paramA";应该是:static NSString* PARAMS = @"paramA";

Reading the full error message allowed me to figure this out: "Duplicate symbol PARAMS". Don't be afraid and try to understand error messages! Sometimes they might even tell you exactly what you did wrong.

阅读完整的错误消息让我明白了这一点:“重复符号参数”。不要害怕并尝试理解错误消息!有时他们甚至可能会确切地告诉您您做错了什么。

回答by kraftydevil

You can get this for method names too!

您也可以为方法名称获取此信息!

I got duplicate symbol _runOnMainQueueWithoutDeadlockingafter adding DBCamera via CocoaPods and it was because both my category on NSObject (NSObject+Tools.h) and the GPUImage dependency file GPUImageOutput.m both had a method called 'runOnMainQueueWithoutDeadlocking'.

duplicate symbol _runOnMainQueueWithoutDeadlocking在通过 CocoaPods 添加 DBCamera 之后得到了,这是因为我在 NSObject (NSObject+Tools.h) 上的类别和 GPUImage 依赖文件 GPUImageOutput.m 都有一个名为“runOnMainQueueWithoutDeadlocking”的方法。

I was fortunate enough to be able to remove my method from code because I wasn't actually using it anymore or anywhere.

我很幸运能够从代码中删除我的方法,因为我实际上不再使用它或在任何地方使用它。

It's probably what I deserve for putting a category on NSObject.

这可能是我在 NSObject 上放置一个类别的应得的。

回答by Fluffhead

In my case, I had imported another project, in order to utilize a library contained within. It resulted my project having two main.m files.

就我而言,我导入了另一个项目,以便利用其中包含的库。这导致我的项目有两个 main.m 文件。

This was even more confusing, since the error didn't show up until several builds later.

这更令人困惑,因为错误直到几次构建之后才出现。