Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

bahlquist

macrumors member
Original poster
Oct 6, 2010
41
0
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?
 
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.
 
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.
 
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?

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

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.

Also check permissions on the /usr/lib folder

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

what happens when you type

ls -lart /usr/lib/*crt*

as the user you are compiling as?

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

In fact, there are no similar looking files in that directory.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.