Error when compiling C program from Unix Terminal

Discussion in 'Mac Programming' started by bahlquist, Oct 6, 2010.

  1. macrumors member

    Joined:
    Oct 6, 2010
    #1
    I am new to programing in C and to using the Unix terminal. I would like to compile a program from the terminal before moving on to anything like Xcode. However I run into a problem when using the command "cc main.c" where main.c is the text file:

    #include <stdio.h>
    main()
    {
    printf ("Hello World!\n");
    }

    (I have used other variants as well.)

    The error I get is: "ld: can't locate file for: -lcrt1.o"

    I just reinstalled Developer Tools. Any ideas on what is wrong?
     
  2. macrumors 65816

    Joined:
    Sep 19, 2009
    #2
    Try gcc. See if that works any better.

    Maybe also test if you actually have compilers installed.

    Code:
    which cc
    Code:
    which gcc
    If these don't print anything, that's your problem.
     
  3. thread starter macrumors member

    Joined:
    Oct 6, 2010
    #3
    Thanks mac2x for your reply.

    Both "which" calls give me a path, so I guess that's not the problem. Using "gcc" gives same error.
     
  4. macrumors 6502a

    Joined:
    Jan 15, 2007
    #4
    How did you install the compilers? If you used xcode did you make sure to use a version appropriate for your OS? This is definitely a library path issue.

    Also check permissions on the /usr/lib folder

    what happens when you type

    ls -lart /usr/lib/*crt*

    as the user you are compiling as?
     
  5. thread starter macrumors member

    Joined:
    Oct 6, 2010
    #5
    I'm not sure how they were originally installed, but I'm supposing that I reinstalled them when I clicked on the "Developer.mpkg" icon. I'm running 10.4.11. The disk I think is for 10.2.

    When I use the command "ls -ld /usr/lib" I get
    "drwxr-xr-x 249 root wheel 8466 Oct 6 20:39 /usr/lib"

    "ls: /usr/lib/*crt*: No such file or directory"

    In fact, there are no similar looking files in that directory.
     
  6. macrumors 603

    Cromulent

    Joined:
    Oct 2, 2006
    Location:
    The Land of Hope and Glory
    #6
    Well that's your problem then. Download Xcode 2.5 from Apples website and away you go.
     
  7. macrumors 65816

    Joined:
    Sep 19, 2009
    #7
    The developer website, that is. :)
     
  8. thread starter macrumors member

    Joined:
    Oct 6, 2010
    #8

Share This Page