View Full Version : Compiling C programs using Xcode gcc

Oct 1, 2010, 04:19 PM
Hey everyone,

So i just imported a folder from my schools server onto my MBP that contained all my C source files that i wrote from a class I took. I have Xcode installed (haven't been able to use it yet), but I am familiar with using Terminal and command line functions.

I am trying to compile my source files in Terminal using gcc, but it's giving me the "command not found error". Since Xcode is installed on my computer, it contains the gcc file on my hard drive. Does anyone know how to make gcc work?


Oct 1, 2010, 06:17 PM
You didn't happen to try to "migrate" Xcode over a Leopard > Snow Leopard install right? Another forum user had that issue not to long ago. Unfortunately, Xcode installs do not survive 10.x updates, though you can unofficially install the previous Xcode on Snow Leopard.

If this is the case, create a free developer account (if you haven't already) and download the latest version of Xcode.


Oct 1, 2010, 07:46 PM
It worked! I downloaded the newest version of Xcode and now it compiles. I tried to -o a .c file but for some reason the program won't execute. any suggestions?

I'm typing:

gcc -Wall -Werror p2-2.c -o p2-2

and when I type "p2-2" and hit return, it says command not found.

Thanks for your help!

Oct 1, 2010, 08:01 PM

. Isn't in your path for safety.


Oct 4, 2010, 02:56 PM
Thanks! everything worked once i added in the ./ I'm just curious though, why do you need to insert that in? I've never had to do it before?

Oct 4, 2010, 03:06 PM
Because the current directory isn't in your path.

./ === current directory

It would be just like typing out:


The ./ is just a shortcut for the current directory.

If I was in the Desktop folder I could type:


And if the Desktop directory was in my PATH I could just type:


Oct 4, 2010, 03:17 PM
Thanks! everything worked once i added in the ./ I'm just curious though, why do you need to insert that in? I've never had to do it before?

If you haven't had to do it before, that means that ".", the current directory, was in your path. That means that if someone made a malicious program called ls in some directory on the server, and "." was before the system path where the real ls lived, when you tried to ls from the directory where the malicious program was installed you might delete your whole home directory, etc.

It is best not to have . in your PATH at all to avoid risks like this. If you want to run a program in the current directory there's a very fast way to do it. Adding . to your PATH is a shortcut that's asking for disaster.

Chances are that in the past you were not configuring your own system, your own PATH, etc. so this dangerous setup wasn't your error. However, you should pretty much expect any well configured system not to default . into your PATH. Just get in the habit of typing ./ and you'll be fine.