I'm trying to compile a simple program with

gcc main.c

and gcc throws me the following error

/usr/bin/ld: cannot find -lc
collect2: error: ld returned 1 exit status

How can I resolve this problem ?

I'm on Linux Mint 17.2, gcc version is 4.8.4

  • 3
    does apt-get install build-essential want to install lots of things? – casey Sep 10 '15 at 19:11
  • 1
    It installed 9 packages and now it works perfectly ! Thank you so much ! – Bilow Sep 10 '15 at 22:02

ld is the linker, i.e. the program that ties together the code that you wrote with the preexisting library code. -lc means the library which is stored in the file libc.a and which is linked because the option -lc is passed to the linker.

libc is the C standard library, which is automatically linked in every program unless you explicitly request that it isn't (which is rarely done except for such things as compiling libc itself, since you pretty much can't do anything without libc, and you definitely can't do anything that's vaguely portable).

You need the package that provides libc.a. You can find it with apt-file search /libc.a (you'll need to install apt-file first, and initialize it by running sudo apt-file update). The package is called libc6-dev; most development packages in Debian and derivatives (including Ubuntu, Mint, etc.) are called libNAME#-dev where NAME is the name of the library collection (which is not always the name of the specific library you link with, for example the libc6 package includes other libraries such as libm) and # is a version number.

The C standard library is needed to build pretty much anything, so it's a dependency of the build-essential package, which you should include if you do any compiling.

  • The missing library is probably not libc.a, which is only needed for linking statically, but libc_nonshared.a which is the static part GCC includes when linking dynamically. – Thomas Erker Sep 12 '15 at 11:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.