Linker Command turns one year old today, and I’m in my last days at the place that I started it for the Summer, so I wanted to share the error behind the name.
Last summer, I was getting really angry at seeing this error come up over and over again. If you’re new to C like I am, and you something that starts like this:
Ld /Volumes/Storage/Users/mike/Library/Developer/Xcode/DerivedData/PedalCharts-gvryltpjsvqnwraultwngecnzbsd/Build/Products/Debug-iphonesimulator/PedalCharts.app/PedalCharts normal x86_64
cd /Volumes/Storage/Users/mike/Documents/Cocoa/Bitbucket/PedalCharts
export IPHONEOS_DEPLOYMENT_TARGET=7.0
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”
ETC ETC ETC
You are going to look at this and say, I have no idea what to do with this garbage. The important stuff is in the second half (and Xcode is much more forthcoming with this than it used to be):
duplicate symbol _OBJC_METACLASS_$_PedalChart in:
/Volumes/Storage/Users/mike/Library/Developer/Xcode/DerivedData/PedalCharts-gvryltpjsvqnwraultwngecnzbsd/Build/Intermediates/PedalCharts.build/Debug-iphonesimulator/PedalCharts.build/Objects-normal/x86_64/PCStaffView.o
/Volumes/Storage/Users/mike/Library/Developer/Xcode/DerivedData/PedalCharts-gvryltpjsvqnwraultwngecnzbsd/Build/Intermediates/PedalCharts.build/Debug-iphonesimulator/PedalCharts.build/Objects-normal/x86_64/PedalChart-45484887584B8F82.o
duplicate symbol _OBJC_CLASS_$_PedalChart in:
/Volumes/Storage/Users/mike/Library/Developer/Xcode/DerivedData/PedalCharts-gvryltpjsvqnwraultwngecnzbsd/Build/Intermediates/PedalCharts.build/Debug-iphonesimulator/PedalCharts.build/Objects-normal/x86_64/PCStaffView.o
/Volumes/Storage/Users/mike/Library/Developer/Xcode/DerivedData/PedalCharts-gvryltpjsvqnwraultwngecnzbsd/Build/Intermediates/PedalCharts.build/Debug-iphonesimulator/PedalCharts.build/Objects-normal/x86_64/PedalChart-45484887584B8F82.o
ld: 2 duplicate symbols for architecture x86_64
Along with, finally, the familiar:
clang: error: linker command failed with exit code 1 (use -v to see invocation)
The important part here is the duplicate symbols. The linker is part of the C architecture that links the functions and variables you write with the places they are used in your code. In this case, the linker is complaining that the class PedalChart has been defined in two places. Today, it’s because I used this typo in my PCStaffView Class:
#import “PedalChart.m”
So, this is a big problem, because, instead of importing the header with the declaration of the class, I’ve tried to import the implementation file. The linker doesn’t like this and will throw the error on build time. This is the most likely cause of the error for me, and it’s due to a typo that can be autocompleted.
Personally, I don’t know why you’d want to link an implementation file, but much of this is way over my head anyway.