Apple Mach-O Linker Error


#1

Hi there,
I’m getting a linker error when trying to compile from page 335. The code ran successfully on page 330, but now not so. Here’s the error below. How do I go about troubleshooting this?

d /Users/robbo/Library/Developer/Xcode/DerivedData/Homepwner-bbkxlkpdlvbsfrfmtsliddntuctl/Build/Products/Debug-iphonesimulator/Homepwner.app/Homepwner normal i386
cd "/Users/robbo/iPhone/Homepwner Ch16"
setenv IPHONEOS_DEPLOYMENT_TARGET 6.1
setenv 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/iPhoneSimulator6.1.sdk -L/Users/robbo/Library/Developer/Xcode/DerivedData/Homepwner-bbkxlkpdlvbsfrfmtsliddntuctl/Build/Products/Debug-iphonesimulator -F/Users/robbo/Library/Developer/Xcode/DerivedData/Homepwner-bbkxlkpdlvbsfrfmtsliddntuctl/Build/Products/Debug-iphonesimulator -filelist /Users/robbo/Library/Developer/Xcode/DerivedData/Homepwner-bbkxlkpdlvbsfrfmtsliddntuctl/Build/Intermediates/Homepwner.build/Debug-iphonesimulator/Homepwner.build/Objects-normal/i386/Homepwner.LinkFileList -Xlinker -objc_abi_version -Xlinker 2 -fobjc-arc -fobjc-link-runtime -Xlinker -no_implicit_dylibs -mios-simulator-version-min=6.1 -framework CoreData -framework UIKit -framework Foundation -framework CoreGraphics -o /Users/robbo/Library/Developer/Xcode/DerivedData/Homepwner-bbkxlkpdlvbsfrfmtsliddntuctl/Build/Products/Debug-iphonesimulator/Homepwner.app/Homepwner

duplicate symbol OBJC_CLASS_BNRItem in: /Users/robbo/Library/Developer/Xcode/DerivedData/Homepwner-bbkxlkpdlvbsfrfmtsliddntuctl/Build/Intermediates/Homepwner.build/Debug-iphonesimulator/Homepwner.build/Objects-normal/i386/BNRItem.o /Users/robbo/Library/Developer/Xcode/DerivedData/Homepwner-bbkxlkpdlvbsfrfmtsliddntuctl/Build/Intermediates/Homepwner.build/Debug-iphonesimulator/Homepwner.build/Objects-normal/i386/AssetTypePicker.o duplicate symbol _OBJC_METACLASS__BNRItem in:
/Users/robbo/Library/Developer/Xcode/DerivedData/Homepwner-bbkxlkpdlvbsfrfmtsliddntuctl/Build/Intermediates/Homepwner.build/Debug-iphonesimulator/Homepwner.build/Objects-normal/i386/BNRItem.o
/Users/robbo/Library/Developer/Xcode/DerivedData/Homepwner-bbkxlkpdlvbsfrfmtsliddntuctl/Build/Intermediates/Homepwner.build/Debug-iphonesimulator/Homepwner.build/Objects-normal/i386/AssetTypePicker.o
ld: 2 duplicate symbols for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)

It seems to be saying I have a duplicate symbol in BNRItem.o & AssetTypePicker.o

  • Is there somewhere I can get some info on what the duplicate is?

Thanks.


#2

Ah, here was the problem. In AssetTypePicker.m:

#import “BNRItem.m” instead of #import “BNRItem.h”


#3

Thanks bigbadrobbo!

After digging the stackoverflow, i found this thread and it gave me a hint where my mistake can be.
Intuitively, i declared our NSUserDefaults global variable in the .h file .
Well, it should’ve been declared in the .m file instead.

I would suggest for the next editions of this book to point our the fact that here, we declared a variable in the .m file.