44

In the gcc manual it is given that "The C standard library itself is stored in ‘/usr/lib/libc.a’". I have gcc installed, but could not find libc.a at the said location. Curious to know where is it located.

I find many .so files in /usr/lib location. What are those?

softwarematter
  • 28,015
  • 64
  • 169
  • 263

5 Answers5

50

If you are looking for libc.a:

$ gcc --print-file-name=libc.a
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/libc.a
JFMR
  • 23,265
  • 4
  • 52
  • 76
rscohn2
  • 899
  • 7
  • 10
  • 6
    This is the most correct answer by far - uses a standard tool to find the location of libc which is *not* standard in any way (as I have found out). – akhan Dec 11 '18 at 18:42
33

A few things:

  • gcc and glibc are two different things. gcc is the compiler, glibc are the runtime libraries. Pretty much everything needs glibc to run.
  • .a files are static libraries, .so means shared object and is the Linux equivalent of a DLL
  • Most things DON'T link against libc.a, they link against libc.so

Hope that clears it up for you. As for the location, it's almost certainly going to be in /usr/lib/libc.a and / or /usr/lib/libc.so. Like I said, the .so one is the more common.

Chris Eberle
  • 47,994
  • 12
  • 82
  • 119
  • Is libc.so dynamically linked and libc.a statically linked? – softwarematter May 08 '11 at 05:16
  • 17
    libc.so and libc.a both provide the same functionality. The difference is that if you link against libc.so, whenever libc.so gets upgraded your program gets the benefit of the upgrade with no changes. However if you link against libc.a all of the functionality is packaged into your program. New updates to libc won't update your program, so it will have to be recompiled. – Chris Eberle May 08 '11 at 05:19
  • 3
    So yes, .so is the dynamically linked one, and .a is the statically linked one. – Chris Eberle May 08 '11 at 05:19
9

If you are on RPM based Linux (Red Hat/CentOS/Fedora/SUSE) then you would get the location of the installed glibc with rpm -ql glibc and rpm -ql glibc-devel .

locate libc.a would get you the location. And to see from where it comes do: rpm -qf /usr/lib/libc.a

Here is what rpm -qi has to tell about these packages

glibc-devel:

The glibc-devel package contains the object files necessary for developing programs which use the standard C libraries (which are used by nearly all programs). If you are developing programs which will use the standard C libraries, your system needs to have these standard object files available in order to create the executables. Install glibc-devel if you are going to develop programs which will use the standard C libraries

glibc:

The glibc package contains standard libraries which are used by multiple programs on the system. In order to save disk space and memory, as well as to make upgrading easier, common system code is kept in one place and shared between programs. This particular package contains the most important sets of shared libraries: the standard C library and the standard math library. Without these two libraries, a Linux system will not function.

Brett Holman
  • 743
  • 6
  • 18
phoxis
  • 60,131
  • 14
  • 81
  • 117
3

You need to install package for static libraries separately: glibc-static.i686

jada12276
  • 129
  • 8
2

On centos 5.8

$ ls -l /usr/lib/libc.a
-rw-r--r--  1 root root 2442786 Apr  8  2010 /usr/lib/libc.a

$ rpm -qf /usr/lib/libc.a
glibc-devel-2.3.4-2.43.el4_8.3

You also have to have the glibc-devel package install under RedHat distributions.

phoxis
  • 60,131
  • 14
  • 81
  • 117