Search code examples
iosxcodemach-o

mach-o linker error duplicate symbol. No imported .m files or declarations in headers


I've come across an error in a project in Xcode. I've been making good progress, and everything has been working reasonably well up until now. After making a few subtle layout changes to one of the pages in my app, when trying to run it - I get a mach-o linker error stating multiple (266!) duplicate symbols.

So far, I have:

  • Been through the code multiple times to ensure I haven't imported any .m files (I haven't)
  • Ensured no declarations in header files (there aren't)
  • Checked for duplicated symbols in different classes within the app, even within .m files which shouldn't be shared (there aren't any)
  • Cleaned the project (no joy)
  • Restarted Xcode
  • Tried running on multiple simulators and real devices (same error persists)
  • Deleting the derived data (thanks for the tip Reinhard, as below in comments) - by opening the organiser (Window --> Organiser (shift-cmd-2) --> projects --> delete derived data). Unfortunately error recurs, even after cleaning and rebuilding.
  • Checked the .pch (precompiled header) file, which is in the supporting files folder in the project navigator - still no joy!

I've looked at a number of similar posts, on this and other sites, and by far the majority of errors seem to be when people import a implementation file. When I've had similar errors in the past, they've been fairly easy to solve with going through the code - usually it's been duplicated variables in differing classes. This time, I've done my best to encapsulate things as well as possible, and I haven't had this issue on this project so far.

I'll post the error message here for now. The code is now posted on GitHub at https://github.com/bentaylor42/iRSI, as it's too long to fit on this page.

    Ld /Users/bentaylor/Library/Developer/Xcode/DerivedData/irsi-acrjzbjeyiktwpglrdrfvwhlnhql/Build/Products/Debug-iphonesimulator/irsi.app/irsi normal i386
cd "/Users/bentaylor/Dropbox/iRSI v2/irsi"
export IPHONEOS_DEPLOYMENT_TARGET=7.1
export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -arch i386 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.1.sdk -L/Users/bentaylor/Library/Developer/Xcode/DerivedData/irsi-acrjzbjeyiktwpglrdrfvwhlnhql/Build/Products/Debug-iphonesimulator -F/Users/bentaylor/Library/Developer/Xcode/DerivedData/irsi-acrjzbjeyiktwpglrdrfvwhlnhql/Build/Products/Debug-iphonesimulator -filelist /Users/bentaylor/Library/Developer/Xcode/DerivedData/irsi-acrjzbjeyiktwpglrdrfvwhlnhql/Build/Intermediates/irsi.build/Debug-iphonesimulator/irsi.build/Objects-normal/i386/irsi.LinkFileList -Xlinker -objc_abi_version -Xlinker 2 -fobjc-arc -fobjc-link-runtime -Xlinker -no_implicit_dylibs -mios-simulator-version-min=7.1 -framework AudioToolbox -framework AVFoundation -framework QuartzCore -framework CoreGraphics -framework UIKit -framework Foundation -Xlinker -dependency_info -Xlinker /Users/bentaylor/Library/Developer/Xcode/DerivedData/irsi-acrjzbjeyiktwpglrdrfvwhlnhql/Build/Intermediates/irsi.build/Debug-iphonesimulator/irsi.build/Objects-normal/i386/irsi_dependency_info.dat -o /Users/bentaylor/Library/Developer/Xcode/DerivedData/irsi-acrjzbjeyiktwpglrdrfvwhlnhql/Build/Products/Debug-iphonesimulator/irsi.app/irsi

duplicate symbol _OBJC_IVAR_$_MainMenuViewController._labelVersion in:
/Users/bentaylor/Library/Developer/Xcode/DerivedData/irsi-acrjzbjeyiktwpglrdrfvwhlnhql/Build/Intermediates/irsi.build/Debug-iphonesimulator/irsi.build/Objects-normal/i386/MainMenuViewController-9C9455DB49A1DC98.o
duplicate symbol _OBJC_IVAR_$_MainMenuViewController._labelCopyright in:
/Users/bentaylor/Library/Developer/Xcode/DerivedData/irsi-acrjzbjeyiktwpglrdrfvwhlnhql/Build/Intermediates/irsi.build/Debug-iphonesimulator/irsi.build/Objects-normal/i386/MainMenuViewController-9C9455DB49A1DC98.o
duplicate symbol _OBJC_IVAR_$_MainMenuViewController._switchPHEM in:
/Users/bentaylor/Library/Developer/Xcode/DerivedData/irsi-acrjzbjeyiktwpglrdrfvwhlnhql/Build/Intermediates/irsi.build/Debug-iphonesimulator/irsi.build/Objects-normal/i386/MainMenuViewController-9C9455DB49A1DC98.o
duplicate symbol _OBJC_IVAR_$_MainMenuViewController._labelPHEM in:
/Users/bentaylor/Library/Developer/Xcode/DerivedData/irsi-acrjzbjeyiktwpglrdrfvwhlnhql/Build/Intermediates/irsi.build/Debug-iphonesimulator/irsi.build/Objects-normal/i386/MainMenuViewController-9C9455DB49A1DC98.o

//... and so on, for 266 duplicated symbols, across multiple classes throughout the app)

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

Solution

  • You have many duplicate .m files in Compile Sources, remove them from your target named "irsi", after that, you should compile successfully. enter image description here

    Btw I think you also should remove the duplicate references from your projects, I have listed some of them in the picture below.

    enter image description here