Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where do library C header files go on Linux

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?

like image 632
djechlin Avatar asked May 23 '12 23:05

djechlin


3 Answers

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.

like image 120
Francis Upton IV Avatar answered Oct 06 '22 00:10

Francis Upton IV


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

$ 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 .h files; those are normally in corresponding -dev packages. So you can find the header files here:

$ 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 manual explains how it searches for header files. Note that this is different and separate from using -l to instruct the linker to link with a certain library.

like image 43
mpontillo Avatar answered Oct 06 '22 00:10

mpontillo


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

  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.

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

  1. /usr/include/
  2. /usr/local/include/
like image 35
akhil tiwari Avatar answered Oct 06 '22 01:10

akhil tiwari