C语言 C 标准库的位置

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5925678/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 08:35:37  来源:igfitidea点击:

Location of C standard library

cgcc

提问by devnull

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.

在 gcc 手册中,给出了“C 标准库本身存储在‘/usr/lib/libc.a’中”。我安装了 gcc,但在上述位置找不到 libc.a。很想知道它在哪里。

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

我在 /usr/lib 位置找到了许多 .so 文件。那些是什么?

采纳答案by Chris Eberle

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.
  • .afiles are static libraries, .someans shared object and is the Linux equivalent of a DLL
  • Most things DON'T link against libc.a, they link against libc.so
  • gcc 和 glibc 是两个不同的东西。gcc 是编译器,glibc 是运行时库。几乎所有东西都需要 glibc 才能运行。
  • .a文件是静态库,.so意味着共享对象,是 DLL 的 Linux 等价物
  • 大多数东西不链接到 libc.a,它们链接到 libc.so

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

希望这可以为您解决问题。至于位置,几乎肯定会在/usr/lib/libc.a和/或/usr/lib/libc.so。就像我说的, .so 更常见。

回答by rscohn2

If you are looking for libc.a:

如果您正在寻找libc.a

$ gcc --print-file-name=libc.a
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/libc.a

回答by phoxis

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 glibcand rpm -ql glibc-devel.

如果您使用基于 RPM 的 Linux(Red Hat/CentOS/Fedora/SUSE),那么您将使用rpm -ql glibc和获取已安装的 glibc 的位置 rpm -ql glibc-devel

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

locate libc.a会给你位置。并查看它的来源: rpm -qf /usr/lib/libc.a

Here is what rpm -qihas to tell about these packages

以下是rpm -qi关于这些包的说明

glibc-devel:

glibc 开发:

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-devel 包包含开发使用标准 C 库(几乎所有程序都使用)的程序所需的目标文件。如果您正在开发将使用标准 C 库的程序,您的系统需要有这些标准目标文件才能创建可执行文件。如果您要开发将使用标准 C 库的程序,请安装 glibc-devel

glibc:

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.

glibc 包包含系统上多个程序使用的标准库。为了节省磁盘空间和内存,以及使升级更容易,通用系统代码保存在一个地方并在程序之间共享。这个特定的包包含最重要的共享库集:标准 C 库和标准数学库。没有这两个库,Linux 系统将无法运行。

回答by jada12276

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

您需要单独安装静态库包:glibc-static.i686

回答by Drew Sullivan

On centos 5.8

在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-develpackage install under RedHat distributions.

您还必须glibc-devel在 RedHat 发行版下安装该软件包。