Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jul 29, 2009, 09: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, 12:01 PM   #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, 12:12 PM   #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, 12:22 PM   #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, 12:24 PM   #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, 12:26 PM   #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, 12:30 PM   #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, 12:39 PM   #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, 12:45 PM   #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, 12:50 PM   #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:	32
Size:	244.0 KB
ID:	185564   Click image for larger version

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

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

Click image for larger version

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

Name:	Screen shot 2009-07-29 at 20.44.12.png
Views:	29
Size:	297.9 KB
ID:	185568  
uaecasher is offline   0 Reply With Quote
Old Jul 29, 2009, 12:55 PM   #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, 01: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, 01: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, 01: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, 02: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, 03: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, 03: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, 06: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, 09: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

Similar Threads
thread Thread Starter Forum Replies Last Post
How do I drag the file in Terminal? wts Mac Basics and Help 6 May 27, 2014 10:49 PM
how to view html file from the terminal hajime Mac Basics and Help 1 Nov 4, 2013 11:57 AM
In OS X 10.8 I clicked this terminal file maxsteel OS X 10.8 Mountain Lion 8 Jun 22, 2013 02:13 PM
Host file Terminal Password DeafRaiders OS X 1 Nov 29, 2012 07:34 AM
Help beginner programer, can't get my terminal to compile. sg001 Mac Programming 6 Jul 31, 2012 12:18 AM

Forum Jump

All times are GMT -5. The time now is 02:44 PM.

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

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