I am learning objective-c and XCode using Stephen Kochan’s book. For one of the assignments, I needed to implement an AddressBook lookup feature from the command line. I used two classes from a previous project, added the files and did not make a copy. All builds fine in XCode, but when I issue the following command at the command line:
clang -fobjc-arc -framework Foundation main.m -o ch19
I get the error:
Undefined symbols for architecture x86_64:
"_OBJC_CLASS_$_AddresBook", referenced from:
objc-class-ref in cc-bx2cgt.o
"_OBJC_CLASS_$_AddressCard", referenced from:
objc-class-ref in cc-bx2cgt.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
No typo in AddresBook, my class name has one “s”. I tried removing the files (AddresBook.h and .m and AddressCard.h and .m) from my project, adding them with and without copying. Building and running the app in XCode works just fine.
How can I “clear” out the references and add them again so that I can compile it from the command line?
Thank you.
You need to add those other files object codes.
clang -fobjc-arc -framework Foundation main.m AddressBook.m -o ch19or compile them to object files and then link them.You should also be using xcodebuild for this, if you want to do it on the command line.