库 C 头文件在 Linux 上的位置

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10729484/
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-08-27 14:23:17  来源:igfitidea点击:

Where do library C header files go on Linux

c++cheaderapt-get

提问by djechlin

Embarrassingly basic question. sudo apt-get install libmemcached6- where do the .h's and .o's or .so's live in a typical install on a Linux machine (Ubuntu)? And, how do I make sure g++ can pick them up?

尴尬的基本问题。 sudo apt-get install libmemcached6- 在 Linux 机器 (Ubuntu) 上的典型安装中,.h 和 .o 或 .so 在哪里?而且,我如何确保 g++ 可以接收它们?

回答by Francis Upton IV

They go to /usr/include and /usr/lib. If you use the -l option (for the libraries) it should find them from these standard places. If you include using <file.h>it should also get it from the right place.

他们去/usr/include 和/usr/lib。如果您使用 -l 选项(对于库),它应该从这些标准位置找到它们。如果你包括使用<file.h>它也应该从正确的地方得到它。

回答by mpontillo

On Ubuntu (and other Debian variants) you can use the dpkgcommand to find out. For example:

在 Ubuntu(和其他 Debian 变体)上,您可以使用该dpkg命令进行查找。例如:

$ dpkg -L libxml2
/.
/usr
/usr/share
/usr/share/doc
/usr/share/doc/libxml2
/usr/share/doc/libxml2/AUTHORS
/usr/share/doc/libxml2/NEWS.gz
/usr/share/doc/libxml2/TODO.gz
/usr/share/doc/libxml2/copyright
/usr/share/doc/libxml2/README
/usr/share/doc/libxml2/changelog.Debian.gz
/usr/share/doc/libxml2/README.Debian
/usr/lib
/usr/lib/libxml2.so.2.7.8
/usr/lib/libxml2.so.2

As you can see, Debian packages don't typically include the .hfiles; those are normally in corresponding -devpackages. So you can find the header files here:

如您所见,Debian 软件包通常不包含这些.h文件;这些通常在相应的-dev包中。所以你可以在这里找到头文件:

$ dpkg -L libxml2-dev
/.
/usr
/usr/share
/usr/share/doc
/usr/share/doc/libxml2-dev
/usr/share/doc/libxml2-dev/AUTHORS
/usr/share/doc/libxml2-dev/NEWS.gz
/usr/share/doc/libxml2-dev/TODO.gz
/usr/share/doc/libxml2-dev/copyright
/usr/share/doc/libxml2-dev/README
/usr/share/doc/libxml2-dev/changelog.Debian.gz
/usr/share/aclocal
/usr/share/aclocal/libxml2.m4
/usr/share/man
/usr/share/man/man3
/usr/share/man/man3/libxml.3.gz
/usr/share/man/man1
/usr/share/man/man1/xml2-config.1.gz
/usr/include
/usr/include/libxml2
/usr/include/libxml2/libxml
/usr/include/libxml2/libxml/HTMLtree.h
/usr/include/libxml2/libxml/tree.h
/usr/include/libxml2/libxml/xmlreader.h
/usr/include/libxml2/libxml/xmlschemastypes.h
...

As for gcc, the manualexplains how it searches for header files. Note that this is different and separate from using -lto instruct the linker to link with a certain library.

至于gcc手册解释了它如何搜索头文件。请注意,这是由不同的独立使用-l,以指示链接链接具有一定的图书馆

回答by akhil tiwari

On Linux and the majority of the Unix-based systems, the libraries may be found on either of these two locations:

在 Linux 和大多数基于 Unix 的系统上,可以在以下两个位置之一找到这些库:

  1. /usr/lib/
  2. /usr/local/lib/
  1. /usr/lib/
  2. /usr/local/lib/

The difference between these two locations is that the latter is used for the third party libraries. So if you have published your own library or have installed one from a third party repository (for instance ppa),those files should go to /usr/local/lib.

这两个位置的区别在于后者用于第三方库。因此,如果您发布了自己的库或从第三方存储库(例如 ppa)安装了一个库,则这些文件应转到/usr/local/lib.

The storage of header files can be understood using the above analogy. The folders are:

头文件的存储可以通过上面的类比来理解。文件夹是:

  1. /usr/include/
  2. /usr/local/include/
  1. /usr/包括/
  2. /usr/local/include/