8

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

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

1 Answer 1

7

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.

1
  • 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. Commented Sep 12, 2015 at 11:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .