Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jul 29, 2009, 08:40 AM   #1
uaecasher
macrumors 65816
 
uaecasher's Avatar
 
Join Date: Jan 2009
Location: Stillwater, OK
Send a message via AIM to uaecasher Send a message via MSN to uaecasher Send a message via Yahoo to uaecasher
how to compile Obj-c file in terminal

hello, I'm reading the "Programming in Obj-C 2.0" book and I didn't understand how to compile the file using terminal.

any help?

thanks
uaecasher is offline   0 Reply With Quote
Old Jul 29, 2009, 11:01 AM   #2
kainjow
Moderator emeritus
 
kainjow's Avatar
 
Join Date: Jun 2000
Assuming the file is called file.m and is located on the Desktop:
Code:
cd ~/desktop
gcc file.m -o file -framework Foundation
Then to run:
Code:
./file
They key thing is to name the file with a .m extension so it's compiled as Objective-C, and to remember to link to whatever frameworks you're using via the -framework argument.
kainjow is offline   0 Reply With Quote
Old Jul 29, 2009, 11:12 AM   #3
uaecasher
Thread Starter
macrumors 65816
 
uaecasher's Avatar
 
Join Date: Jan 2009
Location: Stillwater, OK
Send a message via AIM to uaecasher Send a message via MSN to uaecasher Send a message via Yahoo to uaecasher
I'm getting:

Code:
-bash: gcc: command not found
here is my code:


Code:
gcc Untitled.m -o Untitled -framework Foundation
the file name is Untitled and it's in Home directory
uaecasher is offline   0 Reply With Quote
Old Jul 29, 2009, 11:22 AM   #4
kainjow
Moderator emeritus
 
kainjow's Avatar
 
Join Date: Jun 2000
Did you install Xcode?
kainjow is offline   0 Reply With Quote
Old Jul 29, 2009, 11:24 AM   #5
uaecasher
Thread Starter
macrumors 65816
 
uaecasher's Avatar
 
Join Date: Jan 2009
Location: Stillwater, OK
Send a message via AIM to uaecasher Send a message via MSN to uaecasher Send a message via Yahoo to uaecasher
yes i installed it and tried to build the same app and it worked
uaecasher is offline   0 Reply With Quote
Old Jul 29, 2009, 11:26 AM   #6
mags631
Guest
 
Join Date: Mar 2007
What does the following command in the Terminal output?

Code:
/usr/bin/gcc -v
And try this as well:

Code:
/Developer/usr/bin/gcc -v
mags631 is offline   0 Reply With Quote
Old Jul 29, 2009, 11:30 AM   #7
uaecasher
Thread Starter
macrumors 65816
 
uaecasher's Avatar
 
Join Date: Jan 2009
Location: Stillwater, OK
Send a message via AIM to uaecasher Send a message via MSN to uaecasher Send a message via Yahoo to uaecasher
strange, both give me no such directory

maybe because I'm using snow leopard? how can I install GCC?
uaecasher is offline   0 Reply With Quote
Old Jul 29, 2009, 11:39 AM   #8
dejo
Moderator
 
dejo's Avatar
 
Join Date: Sep 2004
Location: The Centennial State
Quote:
Originally Posted by uaecasher View Post
how can I install GCC?
When you install Xcode, it installs gcc. You said you installed Xcode, right? What is in your /Developer directory? (i.e.: what does 'ls /Developer' say?)
__________________
dejo is offline   0 Reply With Quote
Old Jul 29, 2009, 11:45 AM   #9
mags631
Guest
 
Join Date: Mar 2007
Quote:
Originally Posted by uaecasher View Post
strange, both give me no such directory

maybe because I'm using snow leopard? how can I install GCC?
Do you still have a partition with something other than Snow Leopard (e.g., Leopard)? Was XCode installed under a different version of Mac OS X (i.e., not Snow Leopard)?
mags631 is offline   0 Reply With Quote
Old Jul 29, 2009, 11:50 AM   #10
uaecasher
Thread Starter
macrumors 65816
 
uaecasher's Avatar
 
Join Date: Jan 2009
Location: Stillwater, OK
Send a message via AIM to uaecasher Send a message via MSN to uaecasher Send a message via Yahoo to uaecasher
here are screen shots
Attached Thumbnails
Click image for larger version

Name:	Screen shot 2009-07-29 at 20.43.06.png
Views:	22
Size:	244.0 KB
ID:	185564   Click image for larger version

Name:	Screen shot 2009-07-29 at 20.43.46.png
Views:	12
Size:	273.8 KB
ID:	185565   Click image for larger version

Name:	Screen shot 2009-07-29 at 20.43.53.png
Views:	13
Size:	320.0 KB
ID:	185566  

Click image for larger version

Name:	Screen shot 2009-07-29 at 20.44.04.png
Views:	13
Size:	232.0 KB
ID:	185567   Click image for larger version

Name:	Screen shot 2009-07-29 at 20.44.12.png
Views:	19
Size:	297.9 KB
ID:	185568  
uaecasher is offline   0 Reply With Quote
Old Jul 29, 2009, 11:55 AM   #11
uaecasher
Thread Starter
macrumors 65816
 
uaecasher's Avatar
 
Join Date: Jan 2009
Location: Stillwater, OK
Send a message via AIM to uaecasher Send a message via MSN to uaecasher Send a message via Yahoo to uaecasher
Quote:
Originally Posted by mags631 View Post
Do you still have a partition with something other than Snow Leopard (e.g., Leopard)? Was XCode installed under a different version of Mac OS X (i.e., not Snow Leopard)?
ya, i had leopard (which i think there is where I installed xCode) then i updated to snow leopard and before two days I added dual booting with leopard
uaecasher is offline   0 Reply With Quote
Old Jul 29, 2009, 12:09 PM   #12
mags631
Guest
 
Join Date: Mar 2007
Quote:
Originally Posted by uaecasher View Post
ya, i had leopard (which i think there is where I installed xCode) then i updated to snow leopard and before two days I added dual booting with leopard
OK -- try this:
Code:
/Volumes/Loeprad\ HD/Developer/usr/bin/gcc -v
mags631 is offline   0 Reply With Quote
Old Jul 29, 2009, 12:13 PM   #13
uaecasher
Thread Starter
macrumors 65816
 
uaecasher's Avatar
 
Join Date: Jan 2009
Location: Stillwater, OK
Send a message via AIM to uaecasher Send a message via MSN to uaecasher Send a message via Yahoo to uaecasher
i get this :


Code:
-bash: /Volumes/Loeprad HD/Developer/usr/bin/gcc: No such file or directory

btw what if i delete the old xCode and download iPhone SDK (it include xCode 3.2) (mine is 3.1)
uaecasher is offline   0 Reply With Quote
Old Jul 29, 2009, 12:20 PM   #14
mags631
Guest
 
Join Date: Mar 2007
Quote:
Originally Posted by uaecasher View Post
i get this :


Code:
-bash: /Volumes/Loeprad HD/Developer/usr/bin/gcc: No such file or directory

btw what if i delete the old xCode and download iPhone SDK (it include xCode 3.2) (mine is 3.1)
Reinstalling XCode under Snow Leopard should definitely help.
mags631 is offline   0 Reply With Quote
Old Jul 29, 2009, 01:36 PM   #15
rossipoo
macrumors regular
 
Join Date: Jun 2009
You must install the Command Line tools with XCode. They are optional.
rossipoo is offline   0 Reply With Quote
Old Jul 29, 2009, 02:09 PM   #16
m3kilpat
macrumors regular
 
Join Date: Jul 2009
It would help if this:

Code:
/Volumes/Loeprad\ HD/Developer/usr/bin/gcc -v
had the correct spelling of Leopard.
m3kilpat is offline   0 Reply With Quote
Old Jul 29, 2009, 02:27 PM   #17
daracne
macrumors newbie
 
Join Date: Jun 2009
Judging by the screenshots you posted, it looks like you have a ton of broken symlinks? I would try invoking the actual gcc binary directly by compiling with this command...

Code:
gcc-4.2 MyFile.m -framework Foundation
Or if you just want to verify that method would work, ask for the version number...
Code:
gcc-4.2 -v
If that works, then I would try uninstalling xcode completely and reinstalling it to see if it fixes those symlinks.
daracne is offline   0 Reply With Quote
Old Jul 29, 2009, 05:24 PM   #18
mags631
Guest
 
Join Date: Mar 2007
Quote:
Originally Posted by m3kilpat View Post
It would help if this:

Code:
/Volumes/Loeprad\ HD/Developer/usr/bin/gcc -v
had the correct spelling of Leopard.
That spelling was taken straight from his screenshot.
mags631 is offline   0 Reply With Quote
Old Jul 30, 2009, 08:41 AM   #19
uaecasher
Thread Starter
macrumors 65816
 
uaecasher's Avatar
 
Join Date: Jan 2009
Location: Stillwater, OK
Send a message via AIM to uaecasher Send a message via MSN to uaecasher Send a message via Yahoo to uaecasher
i solved the problem by reinstalling xCode

thanks for your help guys
uaecasher is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
"Permission Denied" when trying to open a file in Terminal Juventino OS X 11 Feb 12, 2011 04:46 PM
Help compiling/running graphics in terminal dflem11 Mac Programming 2 Nov 8, 2010 02:42 PM
How to Compile Multiple files in Xcode? Dj0071 Mac Programming 3 Oct 1, 2008 10:16 PM
How to compile multi file C++ code on mac kbboy Mac Programming 7 Jun 14, 2007 11:07 AM
Command to edit a file in terminal tidyboy Mac Basics and Help 5 Dec 15, 2006 11:49 AM


All times are GMT -5. The time now is 11:33 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC