Xcode, Duplicate symbol _main

前端 未结 10 745
抹茶落季
抹茶落季 2020-11-30 03:14

I have duplicate symbol _main.

The problem is it says \"Duplicate symbol _main in /Users/.../i386/main-B9843B6026D6EFA4.o and /Users/.../i386/main-B9843B6026D6EFA4.o

相关标签:
10条回答
  • 2020-11-30 03:16

    You can get this for method names too!

    I got duplicate symbol _runOnMainQueueWithoutDeadlocking after 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'.

    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.

    0 讨论(0)
  • 2020-11-30 03:23

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

    0 讨论(0)
  • 2020-11-30 03:27

    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:

    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

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

    0 讨论(0)
  • 2020-11-30 03:29

    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.

    0 讨论(0)
  • 2020-11-30 03:35

    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

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

    0 讨论(0)
  • 2020-11-30 03:36

    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.

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

    0 讨论(0)
提交回复
热议问题