Amazon.com Widgets How to Compile obj-C program on mac OS X using gcc compiler
Welcome, Guest. Please login or register.
Did you miss your activation email?
August 21, 2014, 04:58:05 PM
Home Help Search chat Login Register   
News: Read this please.The Great Kangaroo Escape Looking for reviews of the 4th ed on Amazon!   Twitter:  @skochan
                     

+  Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
|-+  Old Stuff
| |-+  Program Examples
| | |-+  Chapter 2
| | | |-+  How to Compile obj-C program on mac OS X using gcc compiler
Pages: [1]   Go Down
Print
Author Topic: How to Compile obj-C program on mac OS X using gcc compiler  (Read 5845 times)
NishAbe
Newbie
*
Posts: 4






« on: October 26, 2010, 12:05:33 PM »

hi All,
I am trying to compile the program in 17 of chapter 2 using terminal interface.
Unfortunately it is not succeeding.

#import <Foundation/Foundation.h>

int main (int argc, const char * argv[]) {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

   int n, number, triangularNumber;
   NSLog (@"What triangular number do you want?");
   scanf ("%i", &number);
   triangularNumber = 0;
   for ( n = 1; n <= number; ++n )
      triangularNumber += n;
   NSLog (@"Triangular number %i is %i\n", number, triangularNumber);
   
    [pool drain];
    return 0;
}

The errors are:


: –framework: No such file or directory
: Foundation: No such file or directory
: error: Foundation.h: No such file or directory
: In function 'main':
:4: error: 'NSAutoreleasePool' undeclared (first use in this function)
:4: error: (Each undeclared identifier is reported only once
:4: error: for each function it appears in.)
:4: error: 'pool' undeclared (first use in this function)
:8: warning: incompatible implicit declaration of built-in function 'scanf'


At terminal I enter command as shown below:

gcc –framework /Developer/SDKs/MacOSX10.5.sdk/System/Library/Frameworks/Foundation.framework/Versions/C/Headers test.m -o prog1


Could you please tell me what is wrong here?
Logged
NishAbe
Newbie
*
Posts: 4






« Reply #1 on: November 01, 2010, 11:36:49 PM »

Hi , Can anyone help please?
Logged
skochan
Administrator
Hero Member
*****
Posts: 3114







« Reply #2 on: November 04, 2010, 11:17:04 AM »

Did you just try the following command line:

Code: (Objective-C)
gcc -framework foundation -std=c99  test.m -o prog1

That's what's listed in the book and what I use all the time

Cheers,

Steve Kochan
Logged
NishAbe
Newbie
*
Posts: 4






« Reply #3 on: November 04, 2010, 10:42:42 PM »

Thanks for the reply , Stephen.

I tried this too. But did not work.
I did not understand what is -std=c99 or -o.

However I am not stuck with this issue. Today I am starting with the 18th chapter.
Just want to say I LOVE YOUR BOOK. Smiley
And hope you will correct all those small typos in the latest version.

As you have mentioned in the book, development with the terminal is not a long term option. I just want to know how to compile and run a basic ObjC program in a terminal.

Do you think we should pass the absolute path to foundation header files along with the command line arguments?
And if that is the case what would be the syntax?

Eager to hear from you....
Logged
skochan
Administrator
Hero Member
*****
Posts: 3114







« Reply #4 on: November 04, 2010, 11:04:54 PM »

The -std=c99 says to support ANSI C-99 standards.  It just allows for some special extensions that were made to the underlying C language at that time (e.g., variable length C arrays).   I haven't checked recently, but by default that standard was not supported by the compiler unless that option was specified. 

The -o option specifies the name of the executable file.  I think that's described in the text.

Why doesn't that command line work for you?  Since you're way past that point, you don't have to bother replying, but I'm curious as to what sort of errors you're getting from that command.

Cheers,

Steve
Logged
NishAbe
Newbie
*
Posts: 4






« Reply #5 on: November 04, 2010, 11:24:24 PM »

Thanks.
I have created a folder progs in the root folder.
The code file is prog1.m.
Then executed the command as below:
gcc -framework foundation -std=c99  prog1.m -o prog1

This is the output that I get:

Aneeshs-Mac-Pro:progs aneesh$ gcc -framework foundation -std=c99  prog1.m -o prog1
prog1.m:1:34: error: Foundation/Foundation.h: No such file or directory
prog1.m: In function 'main':
prog1.m:4: error: 'NSAutoreleasePool' undeclared (first use in this function)
prog1.m:4: error: (Each undeclared identifier is reported only once
prog1.m:4: error: for each function it appears in.)
prog1.m:4: error: 'pool' undeclared (first use in this function)
prog1.m:8: warning: implicit declaration of function 'NSLog'


Logged
Pages: [1]   Go Up
Print
Jump to:  



Login with username, password and session length

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Entire forum contents (c) 2009 classroomM.com. All rights reserved.