Hello, I'm not very familiar with objective c, but I'll give it a go:I'm not sure if this book is old or what, but from all the code I've seen on the apple developer website, you need to do something like
#import <foundation/foundation.h>or something similar, and that should import all the basic classes needed like object, etc. If this book is old perhaps the objc/Object.h is not what needed to be included anymore, as honestly I've never seen that in any example code I've been through on apple's developer website.
Hth, -Michael. On 6/11/2014 9:58 AM, LaMar Upshaw wrote:
Hello, I need some help here. I am learning to program with objective-C using a macbook pro with command line tools from Xcode 5.1, running on os X Mavericks. I'm not sure if the problem is the example code in the beginners guide to objective-c book, or the GCC not being properly installed. Below is the sample code, and the the error given by GCC, along with the GCC version: GCC version: Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/c++/4.2.1 Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn) Target: x86_64-apple-darwin13.2.0 Thread model: posix Sample code: hello.m /* Comments: ** Example written by Pascal Bourguignon ** return status change by Chris B. Vetter ** Added comments in empty {} section by Chris B. Vetter ** int main() changed to int main(void) by Dennis Leeuw ** from comments by Chris B. Vetter */ #include <objc/Object.h> @interface Greeter:Object { /* This is left empty on purpose: ** Normally instance variables would be declared here, ** but these are not used in our example. */ } - (void)greet; @end #include <stdio.h> @implementation Greeter - (void)greet { printf("Hello, World!\n"); } @end #include <stdlib.h> int main(void) { id myGreeter; myGreeter=[Greeter new]; [myGreeter greet]; [myGreeter free]; return EXIT_SUCCESS; } Errors and warnings: gcc -lobjc hello.m -o hello hello.m:11:20: error: cannot find interface declaration for 'Object', superclass of 'Greeter' @interface Greeter:Object ~~~~~~~~~~~~~~~~~~ ^ hello.m:11:12: warning: class 'Greeter' defined without specifying a base class [-Wobjc-root-class] @interface Greeter:Object ^ hello.m:11:19: note: add a super class to fix this problem @interface Greeter:Object ^ hello.m:39:20: warning: class method '+new' not found (return type defaults to 'id') [-Wobjc-method-access] myGreeter=[Greeter new]; ^~~ hello.m:43:12: warning: instance method '-free' not found (return type defaults to 'id') [-Wobjc-method-access] [myGreeter free]; ^~~~ 3 warnings and 1 error generated. Thanks for any help anyone can offer. I really do appreciate it. Lamar ** To leave the list, click on the immediately-following link:- ** [mailto:program-l-request@xxxxxxxxxxxxx?subject=unsubscribe] ** If this link doesn't work then send a message to: ** program-l-request@xxxxxxxxxxxxx ** and in the Subject line type ** unsubscribe ** For other list commands such as vacation mode, click on the ** immediately-following link:- ** [mailto:program-l-request@xxxxxxxxxxxxx?subject=faq] ** or send a message, to ** program-l-request@xxxxxxxxxxxxx with the Subject:- faq
** To leave the list, click on the immediately-following link:- ** [mailto:program-l-request@xxxxxxxxxxxxx?subject=unsubscribe] ** If this link doesn't work then send a message to: ** program-l-request@xxxxxxxxxxxxx ** and in the Subject line type ** unsubscribe ** For other list commands such as vacation mode, click on the ** immediately-following link:- ** [mailto:program-l-request@xxxxxxxxxxxxx?subject=faq] ** or send a message, to ** program-l-request@xxxxxxxxxxxxx with the Subject:- faq