Error when compiling C program from Unix Terminal

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

  1. macrumors member

    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>
    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

    Try gcc. See if that works any better.

    Maybe also test if you actually have compilers installed.

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

    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

    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. macrumors member

    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


    Well that's your problem then. Download Xcode 2.5 from Apples website and away you go.
  7. macrumors 65816

    The developer website, that is. :)
  8. macrumors member


Share This Page