Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

This question already has an answer here:

In the root directory, we can find several 'lib' subfolder, for example, /lib, lib32, lib64, /usr/lib, /usr/lib32, /usr/local/lib.

What are their differences?

share|improve this question

marked as duplicate by Kevin Bowen, Flimm, con-f-use, Raja, psusi Apr 15 '13 at 13:18

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
If that question is not specific enough for you, edit this one with any particular questions you have and we'll vote to re-open it. –  Flimm Apr 15 '13 at 10:23
    
@Flimm Agreed. The below answer was provided during/while I was looking at the new edits in the other question and seems to be more detailed. –  Kevin Bowen Apr 15 '13 at 10:39

1 Answer 1

up vote 4 down vote accepted

/lib contain "essential" libraries that may be needed even in single-user (admin-only) mode and without /usr mounted

/usr/lib are the libraries for the normal user-programs, that mostly can be found under /usr.

/usr/local/lib are the libraries for locally installed programs and packages ie. things you've compiled and installed from source-packages yourself.

In addition to shared and static libraries which are the lib-directories main purpose, you may also find some hierarchies (with their own lib, bin, include and so on) for some larger packages under them.

lib32 and lib64 are used on 64-bits systems to separate libraries for 32-and 64-bits.

share|improve this answer
    
for the specific 'lib' file in '/usr/local/lib', how can I include it in my program ? Thanks –  tqjustc Apr 15 '13 at 17:09
1  
The command ldconfig updates the system's cache over libraries, so after installing a new library, you should run this. There is also a config-file /etc/ld.so.conf which specify where ldconfig will look for new libraries, and you can add unusual library-location - like libraries with the actual lib-files in their own subdirs. /usr/local/lib should already be there, so if your library was installed directly under /usr/local/lib, running ldconfig should be enough. More in part #2 –  Baard Kopperud Apr 16 '13 at 13:19
1  
Now the system knows where the library is, but often you need to specify unusual libraries to the gcc and g++ compilers and linker as well. In your program you use #include to specify the library's header file. To compile: "gcc -Wall -I/path/to/includefile -c myprogram.c" Here it's probably /usr/local/include, which should be found anyway. To link with the library, you would use the command "gcc -L/path/to/library -lnameoflibrary -lotherlibraries myprogram.o" Again, /usr/local/lib should be found automatically, but if the lib was in a subdir, you surely would need to specify. –  Baard Kopperud Apr 16 '13 at 13:25

Not the answer you're looking for? Browse other questions tagged or ask your own question.