Search code examples
xcodeduplicate-symbol

How to find the location of duplicate symbol


I have several files listed in compile sources and it doesn't want to sort by name so I'm stuck having to sort through them by hand looking for duplicates. Is there an easier way to do this? It's only ~100 files but it would be nice to know a more efficient way.

Error example:

...
duplicate symbol _OBJC_CLASS_$_AppDelegate in:
    /Users/xxxx/Library/Developer/Xcode/DerivedData/JOMiPhoneApp-ginylosefnqdjpfprrdipmpewzun/Build/Intermediates/MyApp.build/Debug-iphoneos/MyApp.build/Objects-normal/arm64/AppDelegate-215945057A88172.o
ld: 34 duplicate symbols for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Solution

  • If you pull up the report navigator, select the build with the warning, and then expand the console details for the failed compile, it should describe precisely where both of the duplicate references are (in my example, in AppDelegate.o and ViewController.o, the latter because I "accidentally" did an #import of AppDelegate.m rather than AppDelegate.h in ViewController.m):

    enter image description here

    In the project navigator in left panel, click on the search tab and look for AppDelegate. Anyway, you can search through your entire project like so:

    enter image description here

    You can also search for a symbol by typing command+shift+O (the letter "Oh"):

    search for symbols

    This last approach will only find it if you have the AppDelegate symbol defined in different source files, but it's another avenue to consider.