0

I wrote a program in C.After I compiled it using

gcc -o pr prc.c 

and I got the thing below

/usr/bin/ld:cannot find -lc
collect2: ld returned 1 exit status
6
  • ld is the linker, seems it cannot find -lc. Not sure what that is, yet Commented May 27, 2012 at 18:18
  • 1
    You probably did not install a developer package like libc6-dev and you should compile with gcc -Wall -g pr.c -o pr Commented May 27, 2012 at 18:18
  • 2
    @TonyTheLion: It's trying to link against libc, and cannot find it, for some reason. Commented May 27, 2012 at 18:19
  • @BasileStarynkevitch.....hey ..I still get the same thing!!! Commented May 28, 2012 at 15:54
  • @OliCharlesworth....Thanks for editing my question... I think that's the cause probably...But I am still not able to figure out how do I get this glibc installed. I tried the sudo apt thing and still its not working!! Commented May 28, 2012 at 15:57

2 Answers 2

3

-lc is an abbreviation of libc which is the C run-time library. What ever your *nix distribution is, you need to install glibc and glibc-common through an appropriate installer.

man ld and that should give an insight on the error message. Messages like these indicates that the linker is looking for a missing library. The Name of the library here is libc (replace l with lib).

Sign up to request clarification or add additional context in comments.

Comments

3

The linker (ld) can't find library file libc.{a|so}, the standard C library. See the ld man page for mention of this library (and lc command line option to ld) under section OPTIONS. Quoting:

ld -o <output> /lib/crt0.o hello.o -lc

This tells ld to produce a file called output as the result of linking
the file "/lib/crt0.o" with "hello.o" and the library "libc.a"

You should check to make sure these files are actually missing from your system. On my Ubuntu 10.04 LTS system:

 ~  [88] locate libc.so
/lib/libc.so.6
/lib/tls/i686/cmov/libc.so.6
/usr/lib/libc.so

~  [89] locate libc.a
/usr/lib/libc.a
/usr/lib/xen/libc.a

How you install this missing library will vary based on your distribution. Use your package manage to search for libc. Otherwise, you may want to consider re-installing gcc

4 Comments

downvote(s) without explanation help no one. Feel free to point out errors and I'll be happy to improve/correct my answer.
Well, the actual problem that remains is that I am not able to figure out how do I install this Libc thing. I'm using Ubuntu ultimate 2.9
@Levon...Yes I did that. And it seems like its present in the system already. I got the following thing when I checked, ejjy@Rex:~$ locate libc.so /lib/i386-linux-gnu/libc.so.6 /usr/lib/i386-linux-gnu/libc.so ejjy@Rex:~$ locate libc.a /usr/lib/i386-linux-gnu/libc.a /usr/lib/i386-linux-gnu/xen/libc.a /usr/share/doc/libklibc/README.klibc.arch So why do you think, its not being found??
@ejjy hard to say, at this point it might be easiest to just re-install gcc and be sure to check the development packages too.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.