Compiling C programs using Xcode gcc

Discussion in 'Mac Programming' started by AUSTOOO!, Oct 1, 2010.

  1. AUSTOOO! macrumors newbie

    Aug 23, 2009
    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?

  2. mac2x macrumors 65816

    Sep 19, 2009
    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.
  3. AUSTOOO! thread starter macrumors newbie

    Aug 23, 2009
    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!
  4. lee1210 macrumors 68040


    Jan 10, 2005
    Dallas, TX
  5. AUSTOOO! thread starter macrumors newbie

    Aug 23, 2009
    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?
  6. ulbador macrumors 68000


    Feb 11, 2010
    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:

  7. lee1210 macrumors 68040


    Jan 10, 2005
    Dallas, TX
    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.


Share This Page