PDA

View Full Version : Error when compiling C program from Unix Terminal




bahlquist
Oct 6, 2010, 11:44 PM
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?



mac2x
Oct 7, 2010, 01:24 AM
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.

bahlquist
Oct 7, 2010, 01:33 AM
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.

foidulus
Oct 7, 2010, 02:21 AM
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?

bahlquist
Oct 7, 2010, 11:39 AM
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.

Cromulent
Oct 7, 2010, 11:58 AM
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.


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

mac2x
Oct 7, 2010, 01:09 PM
Well that's your problem then. Download Xcode 2.5 from Apples website and away you go.

The developer website, that is. :)

bahlquist
Oct 7, 2010, 03:27 PM
Well that's your problem then. Download Xcode 2.5 from Apples website and away you go.

Thanks! That worked. I found Xcode 2.5 at:

https://connect.apple.com/cgi-bin/WebObjects/MemberSite.woa/wa/getSoftware?bundleID=19907