Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

uaecasher

macrumors 65816
Original poster
Jan 29, 2009
1,289
0
Stillwater, OK
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
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
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.
 

uaecasher

macrumors 65816
Original poster
Jan 29, 2009
1,289
0
Stillwater, OK
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
 

mags631

Guest
Mar 6, 2007
622
0
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

Guest
Mar 6, 2007
622
0
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)?
 

uaecasher

macrumors 65816
Original poster
Jan 29, 2009
1,289
0
Stillwater, OK
here are screen shots
 

Attachments

  • Screen shot 2009-07-29 at 20.43.06.png
    Screen shot 2009-07-29 at 20.43.06.png
    244 KB · Views: 106
  • Screen shot 2009-07-29 at 20.43.46.png
    Screen shot 2009-07-29 at 20.43.46.png
    273.8 KB · Views: 128
  • Screen shot 2009-07-29 at 20.43.53.png
    Screen shot 2009-07-29 at 20.43.53.png
    320 KB · Views: 115
  • Screen shot 2009-07-29 at 20.44.04.png
    Screen shot 2009-07-29 at 20.44.04.png
    232 KB · Views: 147
  • Screen shot 2009-07-29 at 20.44.12.png
    Screen shot 2009-07-29 at 20.44.12.png
    297.9 KB · Views: 104

uaecasher

macrumors 65816
Original poster
Jan 29, 2009
1,289
0
Stillwater, OK
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

macrumors 65816
Original poster
Jan 29, 2009
1,289
0
Stillwater, OK
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)
 

mags631

Guest
Mar 6, 2007
622
0
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.
 

m3kilpat

macrumors regular
Jul 6, 2009
119
0
It would help if this:

Code:
/Volumes/Loeprad\ HD/Developer/usr/bin/gcc -v

had the correct spelling of Leopard.
 

daracne

macrumors newbie
Jun 23, 2009
16
0
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.