Take the 2-minute tour ×

I want to add my own library to use in c compiling, but don't really know where ubuntu stores it.

share|improve this question
It stores in /usr/lib & /usr/include –  karthick87 Dec 15 '10 at 9:54
i did find my library's in /usr/include how should i go with putting them in? should i just put a header file and a c file near it or should i write the header and the function together in one .h file? –  david25 Dec 15 '10 at 10:06
Libraries and headers are different things, /usr/include does NOT contain libraries, it contains headers which are definitions of functions/objects available from libraries. The question should be improved, it's hard to understand what are you trying to achieve. –  João Pinto Dec 15 '10 at 15:04
add comment

5 Answers

up vote 4 down vote accepted

Based on your comments to your question, I think what you are really asking is "How do I install a custom library I wrote and where should I put it?"

In general, things built locally for others on the machine to user are put into the /usr/local tree. The header file should go into /usr/local/include. The compiled library should go into /usr/local/lib. The .c file is not part of the library, it is part of the source and not something normally not installed for the use of the end user. You will need root access to put files in either of these locations.

To build the library, you will need to build first decide if you want a static or dynamic (shared) library. More information on creating a shared library can be foundin section 3.4, Creating a Shared Library at http://www.linux.org/docs/ldp/howto/Program-Library-HOWTO/shared-libraries.html. (They also have recommendation about where to put stuff -- most developers will have an an opinion or three :-) )

share|improve this answer
add comment

Depending on library, ubuntu stores its libraries mainly in three locations

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

Following is from File System Hierarchy Standard


The /lib directory contains those shared library images needed to boot the system and run the commands in the root filesystem, ie. by binaries in /bin and /sbin.




/usr/local/lib contains local libraries i.e one specific for this system but I can not find references to /usr/local/lib in FHS, it only contains explanation for /usr/local.

share|improve this answer
add comment

Ubuntu follows Filesystem Hierarchy Standard (http://en.wikipedia.org/wiki/Filesystem_Hierarchy_Standard), regular applications libraries should be stored under /usr/lib .

Please note that developing/managing libraries is not a trivial subject, you should read some more detailed documentation, here is a nice tutorial: http://www.yolinux.com/TUTORIALS/LibraryArchives-StaticAndDynamic.html

share|improve this answer
add comment

You should tell the compiler, where it can find your library. Assumed, the path to your library is "/path/to/lib/libfoo.a", you could compile and link your program "hello.c" like this:

gcc -L/path/to/lib -lfoo hello.c

This is not specific to Ubuntu, actually all C-compilers I know support those flags.

share|improve this answer
add comment

In Ubuntu they are found in /usr/include.

share|improve this answer
Header files are in /usr/include. The actual binaries for a library are not stored there. Headers may be considered part of a library, but they have to be installed separately, and they are use to compile programs that use a library. Once a program that uses a library has been compiled, it doesn't need or use the header files anymore. –  Eliah Kagan Aug 30 '13 at 18:05
add comment

Your Answer


