gcc Won't compile .C source code

Discussion in 'Mac Programming' started by moore1879, May 22, 2008.

  1. moore1879 macrumors newbie

    Joined:
    May 22, 2008
    #1
    I can't seem to compile .c source code. I need to be able to in order for make, and make install to work properly. Any suggestions? Here is a sample of what is going on:

    These are the contents of hello.c.

    #include <stdio.h>

    main()
    {
    printf("Hello World");
    }


    gcc hello.c prints:

    hello.c:1:19: error: stdio.h: No such file or directory
    hello.c: In function 'main':
    hello.c:5: warning: incompatible implicit declaration of built-in function 'printf'


    gcc --version prints:

    i686-apple-darwin8-gcc-4.0.1 (GCC) 4.0.1 (Apple Computer, Inc. build 5250)
    Copyright (C) 2005 Free Software Foundation, Inc.
    This is free software; see the source for copying conditions. There is NO
    warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
     
  2. eddietr macrumors 6502a

    Joined:
    Oct 29, 2006
    Location:
    Virginia
    #2
    Did you check to see if stdio.h is in /usr/include/ or some other place where gcc can find it?

    If you do 'gcc -v hello.c' you can see where gcc is looking for stdio.h
     
  3. moore1879 thread starter macrumors newbie

    Joined:
    May 22, 2008
    #3
    I just checked /usr/include and stdio.h is not there. I know absolutely nothing about the C programming language. I just want to be able to install source code. What do I do?
     
  4. Cromulent macrumors 603

    Cromulent

    Joined:
    Oct 2, 2006
    Location:
    The Land of Hope and Glory
    #4
    I assume you have Xcode installed?
     
  5. eddietr macrumors 6502a

    Joined:
    Oct 29, 2006
    Location:
    Virginia
    #5
    Did you install the Apple developer tools?
     
  6. moore1879 thread starter macrumors newbie

    Joined:
    May 22, 2008
    #6
    Yes, that is how I installed gcc, with the developers' tools from the apple installation disk.
     
  7. Sander macrumors 6502

    Joined:
    Apr 24, 2008
    #7
    Something must have gone wrong with the installation. GCC normally should be able to find its standard headers without further effort on your part. You could try reinstalling.

    Incidentally, your test program is not valid C. It should be:

    #include <stdio.h>

    int main(void)
    {
    printf("Hello World\n");
    return 0;
    }

    Cheers,
    Sander
     
  8. lee1210 macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #8
    I would try to reinstall the developer tools.

    What hits do you get if you try:
    locate stdio.h
    ?

    If there are any, you could try to add the option:
    -I /path/to/directory/here

    to your gcc command string.

    -Lee
     
  9. eddietr macrumors 6502a

    Joined:
    Oct 29, 2006
    Location:
    Virginia
    #9
    That's strange. You should have gotten the headers as well then.

    So one thing you might try is reinstalling XCode. It seems you are on Tiger, is that right?

    So the latest version of XCode for Tiger is 2.5. If you're going to reinstall, you might as well use that. You can get it from http://developer.apple.com, go to ADC Member page, register if necessary (if you don't already have an account there), and then do to Downloads->Developer Tools and look for XCode 2.5.
     
  10. Alloye macrumors 6502a

    Joined:
    Apr 11, 2007
    Location:
    Rocklin, CA
    #10
    Do a custom install of Xcode Tools and include UNIX Development Support.
     
  11. moore1879 thread starter macrumors newbie

    Joined:
    May 22, 2008
    #11
    I am going to reinstall the developer tools. I'll let y'all know how it goes.
     

Share This Page